DragonFly BSD
DragonFly submit List (threaded) for 2004-05
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: [PATCH] rand.c updates from FreeBSD RELENG_5


From: Joerg Sonnenberger <joerg@xxxxxxxxxxxxxxxxx>
Date: Wed, 12 May 2004 14:16:19 +0200

On Wed, May 12, 2004 at 06:11:21AM -0500, William M. Grim wrote:
> I have included the patch, but to see what I mean about the current 
> rand(3) not being great, try this code (yes, I know, the seeding could 
> have been done better):
> 
[snip]
>                 cs = rand() % 2;
[snip]

In any good book about the rand() PRNG and in random(3) is a note that the
lower bits have a very low entropy. E.g. chance the code to
	cs = (rand() >> 8) % 2;
provides much better results.

Joerg



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]