chicken-janitors
[Top][All Lists]
Advanced

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

[Chicken-janitors] #218: random not random


From: Chicken Trac
Subject: [Chicken-janitors] #218: random not random
Date: Fri, 23 Apr 2010 21:17:38 -0000

#218: random not random
----------------------+-----------------------------------------------------
 Reporter:  zbigniew  |       Owner:       
     Type:  defect    |      Status:  new  
 Priority:  minor     |   Milestone:  4.6.0
Component:  unknown   |     Version:       
 Keywords:            |  
----------------------+-----------------------------------------------------
 So rand() is completely subpar at generating random numbers in two ways:

 1. Lower bits are not random.  We already work around this in the standard
 manner by scaling the result of a floating-point division.

 2. Nearby seeds don't affect the output much.

 Due to # 2, on Mac OS X we may obtain the same initial random number for a
 minute or more, even though it is seeded with (current-seconds):
 {{{
 while :; do csi -p '(random 1000)'; sleep 5; done
 734
 734
 734
 734
 734
 209
 209
 }}}

 We can fix the problem on OS X by using random(3) instead of rand(3),
 which is present on all BSDs and on Linux.

 Internally, Linux uses random() when rand() is called and some BSDs seem
 to as well.  However, there should be no harm anyway in applying the
 attached patch, which affects linux and bsd.

-- 
Ticket URL: <http://www.irp.oist.jp/trac/chicken/ticket/218>
Chicken Scheme <http://www.call-with-current-continuation.org/>
Chicken Scheme is a compiler for the Scheme programming language.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]