手机
当前位置:查字典教程网 >编程开发 >C语言 >c语言随机数函数示例
c语言随机数函数示例
摘要: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语言string函数的详解

c语言中 基于随机函数的使用详解

c语言中使用BF-KMP算法实例

基于C语言fflush()函数的使用详解

c语言实现二叉查找树实例方法

C++中返回指向函数的指针示例

c语言读取obj文件转换数据的小例子

C语言实现逆波兰式实例

c语言:基于函数指针的两个示例分析

C语言读取BMP图像数据的源码

精品推荐
分类导航