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

commits at source.squeak.org commits at source.squeak.org
Sun Feb 25 00:04:42 UTC 2018


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

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

Name: Kernel-ul.1153
Author: ul
Time: 25 February 2018, 1:02:44.121313 am
UUID: 647960c4-9e41-4ad0-9190-9cac3a97f7ad
Ancestors: Kernel-tonyg.1152

-  When CroquetPlugin's primitiveGatherEntropy is available, use it to initialize the states array of Random instances.

=============== Diff against Kernel-tonyg.1152 ===============

Item was added:
+ ----- Method: Random class>>gatherEntropyInto: (in category 'entropy source') -----
+ gatherEntropyInto: aByteArray
+ 	"Gather good random entropy from a system source and fill up aByteArray with it. Return true upon success, else false."
+ 	
+ 	<primitive: 'primitiveGatherEntropy' module: 'CroquetPlugin'>
+ 	^false!

Item was changed:
  ----- Method: Random>>seed: (in category 'initialization') -----
  seed: anIntegerOrNil
  	"Use the given integer as the seed, or generate one if it's nil."
  
+ 	(anIntegerOrNil isNil and: [ self seedWithRandomBytes ]) ifFalse: [
+ 		| newSeed |
+ 		newSeed := anIntegerOrNil ifNil: [
+ 			(Time utcMicrosecondClock bitShift: 28) bitXor: self hash hashMultiply ].
+ 		(newSeed between: 0 and: 16rFFFFFFFF) ifFalse: [
+ 			newSeed := self hashSeed: newSeed ].
+ 		self initializeStatesWith: newSeed ].
+ 	self generateStates!
- 	| newSeed |
- 	newSeed := anIntegerOrNil ifNil:
- 					[(Time utcMicrosecondClock bitShift: 28) bitXor: self hash hashMultiply].
- 	(newSeed between: 0 and: 16rFFFFFFFF) ifFalse:
- 		[newSeed := self hashSeed: newSeed].
- 	self 
- 		initializeStatesWith: newSeed;
- 		generateStates!

Item was added:
+ ----- Method: Random>>seedWithRandomBytes (in category 'private') -----
+ seedWithRandomBytes
+ 	"Initialize the states array with random bytes from the VM. Return true on success, false on failure."
+ 
+ 	| randomBytes |
+ 	randomBytes := ByteArray new: MTn * 4.
+ 	(self class gatherEntropyInto: randomBytes) ifFalse: [
+ 		"Primitive not available"
+ 		^false ].
+ 	states := Array new: MTn.
+ 	1 to: MTn do: [ :i | 
+ 		states at: i put: (
+ 			"The below code assumes that MTwordMask is 1 << 30 - 1. It avoids LargeInteger operations on 32-bit platforms. It's equivalent to:
+ 			(randomBytes unsignedLongAt: 1 bigEndian: true) bitAnd: MTwordMask"
+ 			((randomBytes at: i * 4 - 3) bitAnd: 16r3F) * 256 +
+ 				(randomBytes at: i * 4 - 2) * 256 +
+ 				(randomBytes at: i * 4 - 1) * 256 +
+ 				(randomBytes at: i * 4)) ].
+ 	^true!



More information about the Squeak-dev mailing list