用C语言随机函数生成100个不大于100的数的具体算法怎么写?

来源:百度知道 编辑:UC知道 时间:2024/06/28 00:04:54
要很很详细的

http://blog.tianya.cn/blogger/post_show.asp?idWriter=0&Key=0&BlogID=382219&PostID=4547421

以上网有详细的说明
/*已经上机通过测试:*/

#include <stdlib.h>
main()
{
int a[100],i; /*定义数组存放100个数*/
for(i=0;i<100;i++)
a[i]=random(100); /*产生100以内的数*/

for(i=0;i<100;i++)
printf("%d ",a[i]); /*打印输入*/
getch();
}

在C语言函数库中包含了一个产生随机数的函数:
int rand( void );
在函数库中对这个函数的说明是:

The rand function returns a pseudorandom integer in the range

0 to RAND_MAX. Use the srand function to seed the pseudorandom

-number generator before calling rand.

而在C语言函数库中是这样定义RAND_MAX的:

/* Maximum value returned by "rand" function
*/
#define RAND_MAX 0x7FFF

所以,函数int rand( void );返回的是一个界于0