服务器之家

服务器之家 > 正文

c语言随机数函数示例

时间:2021-01-18 10:29     来源/作者:C语言程序设计

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("  %6d\n", rand());
}
标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
返回顶部