4-stable and C rand()?

Colin Percival colin.percival at wadham.ox.ac.uk
Mon Apr 7 07:12:31 PDT 2003


At 09:01 07/04/2003 -0500, Eric Timme wrote:
>No matter how many times I run this it seems to alternate between generating
>two different but non-unique sets of values, depending on whether time(0) is
>even or odd..and I can't understand why (values at the end of this message).
>[...] I just want to know
>what I'm doing wrong, and why I can't do this on my FreeBSD machine =\

$ man rand
RAND(3)                FreeBSD Library Functions Manual                RAND(3)

NAME
     rand, srand, rand_r - bad random number generator
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^

  You're not doing anything wrong; rand(3) is explicitly defined to be a bad random number generator.  If you want a slightly better random number generator for non-cryptographic purposes, you could use random(3).

Colin Percival




More information about the freebsd-stable mailing list