[squeak-dev] The Trunk: Kernel-ul.1011.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Apr 2 19:33:03 UTC 2016


Levente Uzonyi uploaded a new version of Kernel to project The Trunk:
http://source.squeak.org/trunk/Kernel-ul.1011.mcz

==================== Summary ====================

Name: Kernel-ul.1011
Author: ul
Time: 2 April 2016, 9:22:40.391347 pm
UUID: 924b2c29-5e11-4abb-aeb5-355380a4e56a
Ancestors: Kernel-ul.1010

Normalize the created LargePositiveInteger in Random >> #nextLargeInt:.

=============== Diff against Kernel-ul.1010 ===============

Item was changed:
  ----- Method: Random>>nextLargeInt: (in category 'accessing') -----
  nextLargeInt: anInteger
  	"Answer a random integer value from the interval [1, anInteger]. This method works for arbitrarily large integers."
  
  	| byteCount bigRandom result firstDigit |
  	byteCount := anInteger digitLength + 4. "Extend the space with at least 32 bits for a fairer distribution."
  	bigRandom := LargePositiveInteger new: byteCount.
  	self nextBytes: byteCount into: bigRandom startingAt: 1.
+ 	bigRandom := bigRandom normalize. "Make sure that there are no leading zero bytes."
  	result := anInteger * bigRandom bitShift: -8 * byteCount.
  	"Avoid using LargeInteger arithmetic for +1 in most cases."
  	result isLarge ifFalse: [ ^result + 1 ].
  	(firstDigit := result digitAt: 1) = 255 ifTrue: [ ^result + 1 ].
  	result digitAt: 1 put: firstDigit + 1.
  	^result
  	!



More information about the Squeak-dev mailing list