如果我不指定srand()函数,并兰特()用什么种子? [英] If I don't specify srand(), what seed does rand() use?

查看:165
本文介绍了如果我不指定srand()函数,并兰特()用什么种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    int r;
    int i;
    for (i = 0; i < 100; i++)
    {
        r = rand() % 100 + 1;
        printf("%d\n", r);
    }
    return 0;
}

我一直在试图随机数,但有一天,我忘了让函数srand()中,但兰特()功能依然可以随机号码(相同的序列)。

I've been trying to random number but one day, I forgot to put srand() in, but the rand() function can still random a number (the same sequence).

的问题是,如果我不指定它是用什么种子?

The question is, what seed does it use if I don't specify it?

推荐答案

如果函数srand不叫,兰特就如同函数srand(1)被调用。

If srand is not called, rand acts as if srand(1) has been called.

<一个href=\"http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.13.html#rand\">http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.13.html#rand

这篇关于如果我不指定srand()函数,并兰特()用什么种子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆