Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

May near seeds in random number generation give similar random numbers?

I'm using sequential seeds (1,2,3,4,...) for generation of random numbers in a simulation. Does the fact that the seeds are near each other make the generated pseudo-random numbers similar as well?

I think it doesn't change anything, but I'm using python

Edit: I have done some tests and the numbers don't look similar. But I'm afraid that the similarity cannot be noticed just by looking at the numbers. Is there any theoretical feature of random number generation that guarantees that different seeds give completely independent pseudo-random numbers?

like image 452
Homero Esmeraldo Avatar asked Jun 05 '12 16:06

Homero Esmeraldo


2 Answers

There will definitely be a correlation between the seed and the random numbers generated, by definition. The question is whether the randomization algorithm is sufficient to produce results that seem uncorrelated, and you should study up on the methods for evaluating randomness to answer that question.

You are right to be concerned though. Here are the results from Microsoft's C++ rand function with seed values from 0 to 9:

   38  7719 21238  2437  8855 11797  8365 32285 10450 30612
   41 18467  6334 26500 19169 15724 11478 29358 26962 24464
   45 29216 24198 17795 29484 19650 14590 26431 10705 18316
   48  7196  9294  9091  7031 23577 17702 23503 27217 12168
   51 17945 27159   386 17345 27504 20815 20576 10960  6020
   54 28693 12255 24449 27660 31430 23927 17649 27472 32640
   58  6673 30119 15745  5206  2589 27040 14722 11216 26492
   61 17422 15215  7040 15521  6516 30152 11794 27727 20344
   64 28170   311 31103 25835 10443   497  8867 11471 14195
   68  6151 18175 22398  3382 14369  3609  5940 27982  8047
like image 55
Mark Ransom Avatar answered Nov 15 '22 20:11

Mark Ransom


I have found measurable, but small, correlations in random numbers generated from the Mersenne Twister when using sequential seeds for multiple simulations--the results of which are averaged to yield final results. In python on linux, the correlations go away if I use seeds generated by the system random function (non pseudo random numbers) via random.SystemRandom(). I store SystemRandom numbers in files and read them when a seed is needed in a simulation. To generate seeds:

import random
myrandom = random.SystemRandom
x = myrandom.random       # yields a number in [0,1)
dump x out to file...

Then when seeds are needed

import random
read x from file...
newseed = int(x*(2**31))  # produce a 32 bit integer
random.seed(newseed)
nextran = random.random()
nextran = random.random()...
like image 32
BugFinder Avatar answered Nov 15 '22 19:11

BugFinder