[FIX] RandomFix-sr

Stephan Rudlof sr at evolgo.de
Sat Sep 21 19:11:28 UTC 2002


Speeds up Random and fixes some comments.
I have made an extra class (instead of patching Random directly) to be able
to *test* these improvements.

Greetings,

Stephan


"Change Set:		RandomFix-sr
Date:
		21 September 2002
Author:
		Stephan Rudlof

>From the class comment of BRandom:

BRandom:
- simplified Random with corrected comments.
- faster as the original (more than 25%).
- no changed semantics
	(should give exactly the same results as Random (except for the errorneous
seed 0)).
- could replace Random (by merging the methods and removing obsolete inst
vars in Random).

Since Squeak Floats are working with 53 bits for the mantissa, Random
nextValue has been simplified (see BRandom nextValue).
Precision is sufficient...
	(16r7FFFFFFF * 16r000041A7) asFloat asInteger = (16r7FFFFFFF * 16r000041A7)
...since Float works with 53 bits and we need less than 48 (46 without sign
bit):
	(16r7FFFFFFF * 16r000041A7) hex '16r20D37FFFBE59'
.

The comments are corrected regarding the border cases (min and max values).


Test:

| bc rand irand |
bc _
[:r :num |
	num timesRepeat: [r next].
].

rand _ Random new.
irand _ BRandom seed: rand seed.
{
	{ [bc value: rand value: 100000] timeToRun. [bc value: irand value: 100000]
timeToRun }.
	{ rand next. irand next }
}
"
-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RandomFix-sr.1.cs.gz
Type: application/x-gunzip
Size: 1406 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20020921/ea608897/RandomFix-sr.1.cs.bin


More information about the Squeak-dev mailing list