[squeak-dev] Re: The Squeak Random Number Generator

Jerome Peace peace_the_dreamer at yahoo.com
Mon Sep 8 04:20:21 UTC 2008


[squeak-dev] The Squeak Random Number Generator


***
>Jim Rosenberg jr at amanue.com 
>Sun Sep 7 02:45:41 UTC 2008  wrote:
>
>
>I'm getting very queasy feelings about Random.

Good. Best thing to do with feelings like that is write sunit tests.
Random will either pass them or reveal its limitations.

Then you will know and the queasy feelings will go away replaced by
feelings of certainty one way or the other.

There are several things Random is known to fail at.

It silently accepts out of range seeds. 
Then it will return out of range fp fractions for a while.

Try a printit on:
Random new seed: 24 factorial 
		; next  .

It will also only choose odd large Integers.

This is being tracked on mantis:

http://bugs.squeak.org/view.php?id=7142
LargerInteger>>atRandom produces insufficient random bits	 

See the report for more info and a smoke test.

The other danger with Random is that it can get used in ways
 that are not appropriate for it.

It essentially cycles thru only 2**31-1 values which #next returns as a fraction.
The fp numbers have 53 bit mantissas and it is
 easy to assume the fractions have a 53 bit resolution. 
Which of course would be incorrect. 

So #getInt: for ints greater than 2**32 would leave out some choices.
For ints less than that many would not have
 a strictly even chance of being picked. Think about:

gen := Random new .

gen getInt: 3 * ( 2 raisedTo: 30 ) .

A third of possible choices would be
 twice as likely as the others two thirds.


Yours in curiosity and service, --Jerome Peace

>
><...>



***


      



More information about the Squeak-dev mailing list