I have forgotten a small fix in Random in the last version.
Greetings,
Stephan
"Change Set: RandomFix-sr v2 Date: 26 September 2002 Author: Stephan Rudlof
Random: - corrected: >>seed: needs to call initialize just once.
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 } }
History: v2 : Random>>seed: correction v1 : BRandom stuff "
squeak-dev@lists.squeakfoundation.org