0

I wrote a random graph generation program that generates a /single/ random graph. Typically, a run of the program requires about 50 random integers. As you could have predicted I then had a need to generate a stream of random graphs.

So taking the lazy way I wrapped my graph gen program in a perl script and passed it a seed generated randomly by the perl script. FWIW my perl code to generate the seed was

my ($runCt) = 40000;
srand();
   :
my ($seed) = int(rand($runCt*$runCt));

Via the perl script I ran my graph gen program 40,000 times; all 40,000 seeds were unique.

However, of all the graphs generated only 256 of them were unique. Is 256 a coincidence? My suspicion is that RNGs aren't designed to be very "resistant" to different seeds. Can somebody confirm my suspicion or provide a better reason for why I am getting so few "random streams"?

Obviously I could refactor the graph gen program so that with a single seed it generates all 40,000 graphs but I'd be curious to know what is happening here.

Míle buíochais,

healyp
  • 135
  • 1
  • 4
  • Maybe add a perl tag, but from http://perldoc.perl.org/functions/srand.html "Do not call srand() (i.e., without an argument) more than once per process. The internal state of the random number generator should contain more entropy than can be provided by any seed, so calling srand() again actually loses randomness." – doctorlove Oct 25 '13 at 08:28
  • 1
    If I understand you correctly, you generate the same 50 random integers from different seeds. The odds should be terribly small: Take a look at http://stackoverflow.com/questions/12150354/can-two-prngs-produce-the-same-number-with-different-seeds. Can we see the random graph generator code, to see if there is a problem in that program? – ljgw Oct 25 '13 at 08:52
  • @doctorlove: Although it's not so clear from the code snippet above `srand()` is called only once in perl script. – healyp Oct 25 '13 at 12:38
  • Mea culpa. The problem lies with the RNG I was relying on. LEDA provides a `random_source` which you can initialise to always provide an int in a specific range. Once I threw away that convenience and used the default `rand()` and `srand()` functions in my C++ code I got much more predictable output: 39997 uniques out of 40000. Lesson learnt :-). Thanks to both for replying. – healyp Oct 25 '13 at 12:43

0 Answers0