如何使用C构造一个伪随机数生成器生成0-1之间的数?
A: srand((unsigned)time(NULL));
a = rand() % 10 / 10;
B: srand((unsigned)time(NULL));
a = rand() % 11 / 10;
C: srand((unsigned)time(NULL));
a = rand() % 10 / 11;
D: srand((unsigned)time(NULL));
a = rand() % 9 / 10;
A: srand((unsigned)time(NULL));
a = rand() % 10 / 10;
B: srand((unsigned)time(NULL));
a = rand() % 11 / 10;
C: srand((unsigned)time(NULL));
a = rand() % 10 / 11;
D: srand((unsigned)time(NULL));
a = rand() % 9 / 10;
举一反三
- 下面哪一项时是C语言的随机数函数? A: rand(); B: srand(); C: Srand(); D: Rand();
- 下面哪一个函数在C语言的随机数生成中没有被用到? A: int rand(void) B: void srand(unsigned int seed) C: time_t time( time_t *second ) D: char* strcpy(char* destination, const char* source);
- 下面哪个函数用于生成随机数? A: srand() B: rand() C: random() D: 以上都不对
- 下列哪条语句能真正设置随机数种子( )。 A: srand(time(NULL)); B: stand(1) C: stand(50) D: stand(500)
- 下面哪条语句可以生成0-9之间的随机数 A: magic=rand()/10; B: magic=rand()%10; C: magic=rand()/10+1; D: magic=rand()%10+1;