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());
}
相关文章
c++ error:crosses initialization of问题解决分析
这篇文章主要介绍了c++ error:crosses initialization ofde 问题解决分析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-08-08
C语言中isdigit()函数和isxdigit()函数的用法
这篇文章主要介绍了C语言中isdigit()函数和isxdigit()函数的用法,用来判断字符师傅为阿拉伯数字和16进制数字,需要的朋友可以参考下2015-08-08


最新评论