源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c语言随机数函数示例

  • 时间:2022-05-31 04:28 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c语言随机数函数示例
[b]void srand( unsigned int seed ); [/b]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.
[u]复制代码[/u] 代码如下:
#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()); }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部