c语言随机数函数示例_C语言教程-查字典教程网
c语言随机数函数示例
c语言随机数函数示例
发布时间:2016-12-28 来源:查字典编辑
摘要:voidsrand(unsignedintseed);headfileisRemarksThesrandfunctionsetsthesta...

void srand( unsigned int seed );

head file is <stdlib.h>

Remarks

The srand function sets the starting point for generating a series of pseudorandom

integers. To reinitialize the generator, use 1 as the seed argument. Any other value for

seed sets the generator to a random starting point. rand retrieves the pseudorandom

numbers that are generated. Calling rand before any call to srand generates the same

sequence as calling srand with seed passed as 1.

复制代码 代码如下:

#include <stdlib.h>

#include <stdio.h>

#include <time.h>

void main( void )

{

int i;

/* Seed the random-number generator with current time so that

* the numbers will be different every time we run.

*/

srand((unsigned)time(NULL));

/* Display 10 numbers. */

for( i = 0; i < 10;i++ )

printf(" %6dn", rand());

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新C语言学习
    热门C语言学习
    编程开发子分类