[squeak-dev] The Trunk: Kernel-bf.899.mcz

Bert Freudenberg bert at freudenbergs.de
Tue Feb 10 15:43:19 UTC 2015


On 10.02.2015, at 15:37, commits at source.squeak.org wrote:
> 
> Bert Freudenberg uploaded a new version of Kernel to project The Trunk:
> http://source.squeak.org/trunk/Kernel-bf.899.mcz
> 
> ==================== Summary ====================
> 
> Name: Kernel-bf.899
> Author: bf
> Time: 10 February 2015, 4:37:05.988 pm
> UUID: 1cc7d0c6-0a3d-457f-9609-fa508d11310e
> Ancestors: Kernel-eem.898
> 
> Fix random for Really Large Integers.
> 
> =============== Diff against Kernel-eem.898 ===============
> 
> Item was changed:
>  ----- Method: Random>>nextInt: (in category 'accessing') -----
>  nextInt: anInteger
>  	" Answer a random integer in the interval [1, anInteger]. anInteger should be less than 16r80000000. "
> 
>  	anInteger strictlyPositive ifFalse: [ self error: 'Range must be positive' ].
> + 	"avoid Float arithmetic in #next to work with LargeInts"
> + 	^ ((seed := self nextValue) asInteger * anInteger // M asInteger) + 1!
> - 	^ (self next * anInteger) truncated + 1!


We might want to do something better if anInteger > 16r80000000, because that's the maximum number of different random integers we can produce. We would need to call nextValue twice (or more times) to produce enough randomness.

My fix just solves the immediate problem of running into infinite Floats.

- Bert -



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4115 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150210/89c7bfac/smime.bin


More information about the Squeak-dev mailing list