What does the integer while setting the seed mean?

余生颓废 提交于 2019-11-30 08:51:06
kometonja

A random seed (or seed state, or just seed) is a number (or vector) used to initialize a pseudorandom number generator.

For a seed to be used in a pseudorandom number generator, it does not need to be random. Because of the nature of number generating algorithms, so long as the original seed is ignored, the rest of the values that the algorithm generates will follow probability distribution in a pseudorandom manner.

-- wikipedia

So, random function could be implemented like this:

int rand_r(unsigned int *seed)
{
    *seed = *seed * 1103515245 + 12345;
    return (*seed % ((unsigned int)RAND_MAX + 1));
}

(sample taken from glibc)

In the old days, there were books that contained pages and pages of random digits (in a random order, of course).

I like to think of set.seed(x) as telling the computer to start reading random numbers from page x in a huge book of random numbers. x has nothing to do with the data, but how the algorithm for choosing random numbers should begin.

This might be a bit facile, but I like the analogy.

It is just a number used to set seeds for the random number generator. It has nothing to do with your data. If you don't explicitly provide a seed, a new one is created from the current time.

See the ?set.seed help page for plenty of details about it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!