用C语言生成随机10-20之间的整数

随机函数,需要等概率生成
是等概率的么?

第1个回答  2008-03-30
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
int i;

printf("Ten random numbers from 10 to 20\n\n");
for(i=0; i<10; i++)
printf("%d\n", (rand() %10)+10);
return 0;
} /*这个你每次运行程序,出现的随机数顺序都一样。
下面的这个才是随时间日期不同而生成的随机数*/

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

int main(void)
{
int i;

randomize();
printf("Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
printf("%d\n", rand() % 100);
return 0;
}
第2个回答  2008-03-30
随机数发生函数是
int a = rand();
头文件是stdlib.h本回答被提问者采纳
第3个回答  2008-03-30
随机数%20+10