Re: Way for computing random primes in standard C.



On 2006-02-28, Ben Bacarisse <ben.usenet@xxxxxxxxx> wrote:
On Mon, 27 Feb 2006 21:19:19 -0800, websnarf wrote:
As one final comment -- using the ANSI C's rand() is bad because the
state size is so small

I don't think the standard mandates any state size, does it? I don't
think there is nothing to stop rand() being a very high quality generator.

Historically, srand() returned the state of the generator in an
unsigned int, and allowed you to restart or resume sequences by
passing that value back to srand(). This is obviously incompatible
with a high-quality implementation, which is why the BSD world got
random() and srandom().

Said usage of rand() seems to be thoroughly deprecated and nearly
forgotten nowadays, although traces can still be found. Feeding
"return the old seed" to Google yields quite a few variants of the old
BSD random(3) man page's discussion of the issue.

Nonetheless, on a lot of platforms rand() still gets you a low-quality
generator. Always check the documentation...

--
- David A. Holland
(the above address works if unscrambled but isn't checked often)
.



Relevant Pages

  • Re: rand()
    ... Any other value for seed sets the generator to a random starting ... rand retrieves the pseudorandom numbers that are generated. ... rand before any call to srand generates the same sequence as calling srand ... appear to repeat on successive 'runs' is to use the system time, ...
    (microsoft.public.vc.mfc)
  • Re: Floating point load-store behaviour.
    ... This should be "int main". ... calling srand(), you're interfering with the generator. ... You should call srand() exactly once, ...
    (comp.lang.c)
  • Re: randomizing trouble
    ... number generator using gawk did not work because all 3 times it was run ... rand() returns a small decimal and srand() takes an integer. ...
    (comp.lang.awk)
  • Re: Quality of rand()
    ... > Can any tell me why rand() is such a bad pseudo-random number generator. ... Linear Congruential Generator. ... random number generator (RNG), but many security-sensitive ... of tests that evaluate the security weaknesses of a RNGs: ...
    (comp.lang.cpp)
  • Re: Rand number generation
    ... rand() is an interface for three different uniform random number ... You can use any one of three generator algorithms, ... This method generates double precision values in the ... algorithm, the default in MATLAB Versions 5 through 7.3. ...
    (comp.soft-sys.matlab)