Bug 000103

When Created: 07/29/1996 00:05:59
Against DJGPP version: 2.00
By whom:
Abstract: rand() has short period
rand() has a period of less than 30 million, even though it uses
64 bits of state. Very simple, fast generators that just do a
multiply and add are available that have the maximum possible
period and provably good characteristics. I'll provide one.

Note added: 08/16/1996 08:05:26
By whom:
How did you find this short period : I tried it on my machine and could not find any short period (it went over 1 billion 300 millions iterations with no repeat...).

However, if it was the case, removing the next =(next>>27)^(next<<15); instruction should suffice, you hence get a plain linear congruential generator, and as  2**64 and 1103515245 are prime in pairs, period will be 2**64...

Finally, if you want to improve such a generator you may change the congruent values :

next=16807*next (mod 2147483647) has been used with much success for some time.

Solution added: 08/18/1996 04:00:00
By whom:
Remove the line : next=(next>>15)^(next<<27);
from function rand(). You get a normal long period random nr generator

You can also change all the (long long) types to (unsigned long), the (unsigned long) generator has a perios over 4 billion, which is more than enough. And I think rand() will be more rapid, and more alike to other ANSI implementations.

Fixed in version on 04/13/1999 08:00:19
By whom:

  webmaster     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010