What does the integer while setting the seed mean?

前端 未结 3 978
清酒与你
清酒与你 2020-12-30 02:11

I want to randomly select n rows from my data set using the sample() function in R. I was getting different outputs each time and hence used

3条回答
  •  悲哀的现实
    2020-12-30 03:03

    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)

提交回复
热议问题