c语言随机数函数 c语言随机数函数示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

c语言随机数函数 c语言随机数函数示例

  2021-03-19 我要评论
想了解c语言随机数函数示例的相关内容吗,在本文为您仔细讲解c语言随机数函数的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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());
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们