我的C/C++学习----随机数

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void main()
{
    
    float s;
    srand((int)time(0));
    s = (float)rand() / RAND_MAX;
    s = 3 + (5 - 3) * s;   //[3,5]之间float数  [3,5]之间整数 s = rand() % 2 + 4  
    printf("%f\n", s);
    while (1);

}

 

posted @ 2018-07-21 14:44  LifeOverflow  阅读(77)  评论(0)    收藏  举报