srandomdev() vs srandom() vs arc4random()

Charles Swiger cswiger at mac.com
Tue May 24 20:06:53 PDT 2005


On May 24, 2005, at 9:13 PM, Nicolas Blais wrote:
> I would like to know how "random" (that is, how inprobable a  
> pattern will
> appear) if I use srandom(time(NULL)) instead of srandomdev().
> Also, would arc4random() be any better in getting the least pattern  
> creation.
> Finally, is there is a way to check if the call srandomdev() exists  
> on other
> OSes?

srandom() is an adequate RNG, but it tends to have poor distribution  
of numbers (ie, specific bit patterns are more likely than others).   
You might want to consider the Mersenne Twister RNG:

http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

...which has appeared under both a GPL and a BSD-flavored license  
over it's history.

-- 
-Chuck




More information about the freebsd-questions mailing list