如何在c语言编写一个程序,随机抽取10个10-99的数

来源:百度知道 编辑:UC知道 时间:2024/09/26 20:21:04
有关rand函数的部分请解释详细点 谢谢了

int c;
c=rand()%90+10;
rand()就是随机选0~32767之间的一个数。
%90会随机生成0-89的数,再+10就成了10-99了。

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int n=10;
srand((unsigned)time(NULL));
while(n--)
{
int rnd=rand()%90+10;
printf("%d\n",rnd);
}
return 0;
}

//
40
33
72
36
83
10
42
95
49
76

int s = rand()%90 + 10

再循环十次

rand()%90+10是10~99的数.

rand()其实是伪随机数,要产生真正的随机数可以用srand()和time.下面是msdn的内容.
Generates a pseudorandom number. A more secure version of this function is available, see rand_s.

int rand( void );

Return Value
rand returns a pseudorandom number, as described above. There is no error return.

Remarks
The rand function returns a pseudorandom integer in the range 0 to RAND_MAX (