Randomness and reseeding?

Pedro Gimeno Fortea parigalo at formauri.es
Wed Dec 13 20:10:45 CET 2006

On 12/12/2006 07:58:45 PM, Susan Margulies wrote:

> Hello, everyone! I am generating many, many numbers between 0 and 1.  
> I am using gmp_randclass and setting it to gmp_randinit_default, and  
> then seeding it with a read from /dev/random/ using some code gotten  
> off the web.
> However, I began to notice that as I did more and more trials (like a  
> million), it seemed as if I was loosing the randomess. I was not  
> reseeding my random number generator... should I do that? If so,  
> after about how many trials?

No, that should not be necessary. The old LCG code needed a change in  
both seed and parameters to mantain long-term randomness. LCG is not  
the default in recent versions of GMP; it has been superseded by  
Mersenne Twister, which has good long-term properties and has a very  
large period: the sequence is only repeated after drawing 2^19937-1  

What version of GMP are you using?

> I noticed experimentally that if I reseeded too often from  
> /dev/random, the first time it reads 128 bytes, and the rest of the  
> times it only reads 8 bytes. Maybe it hasn't saved up enough  
> randomess between reads?

Yep, that should be the cause. However, as Linas has already pointed
out there should be no need to use it.

> I also tried combinations of reading from /dev/random and reseeding  
> using the system time. Seeding from /dev/random defintely seems to  
> work better.

I'm not aware of any problems related to the current seeding procedure  
of Mersenne Twister but if you give a more accurate definition of  
"better" maybe it can be studied.

In any case, there are plans for replacing the current seeding  
procedure in a future GMP version.

> I can see that I really don't understand these random number  
> generators. Can someone advise me how to generate 2 million numbers  
> between 0 and 1 with a uniform distribution? How can I find a really  
> high quality seed?

Ideally, every seed is as 'high quality' as any other seed; even seeds  
like 1 or 2 should be 'high quality' and yield independent sequences.  
Maybe the current seeding procedure does not get close enough to that  
ideal for practical uses; if that's the case then maybe you have to  
follow the section of the manual related to reporting bugs.

-- Pedro Gimeno

More information about the gmp-discuss mailing list