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@evolgo.de writes:
Speeds up Random and fixes some comments.
Darn.. I thought this was going to be some kind of nifty hack applying random "fixes" to my image. :)
-Simon
Simon Michael wrote:
Stephan Rudlof sr@evolgo.de writes:
Speeds up Random and fixes some comments.
Darn.. I thought this was going to be some kind of nifty hack applying random "fixes" to my image. :)
This is a neat idea! Just applying it, say once a day, and the image improves every day...
Anyone volunteering for it?
A serious note: I've hesitated to call it a FIX, since nothing was semantically broken. But I think it makes sense to incorporate it into the standard system (however defined), since Random becomes - becomes faster, - becomes simplified, and - gets corrected *comments*.
Greetings,
Stephan
-Simon
squeak-dev@lists.squeakfoundation.org