Random.st
changeset 3431 4ece2027bd33
parent 3414 bfae9f81787a
child 3675 058f3f83eae0
equal deleted inserted replaced
3430:9f50ed777fd0 3431:4ece2027bd33
   271      But it should be much better than what is commonly used in older
   271      But it should be much better than what is commonly used in older
   272      programs (current time) or even a constant."
   272      programs (current time) or even a constant."
   273 
   273 
   274     |hash|
   274     |hash|
   275 
   275 
   276     hash := MD5Stream new.
       
   277 
       
   278     RandomSalt isNil ifTrue:[
   276     RandomSalt isNil ifTrue:[
   279         RandomSalt := 1.
   277         RandomSalt := 1.
   280     ] ifFalse:[
   278     ] ifFalse:[
   281         RandomSalt := RandomSalt + 1.
   279         RandomSalt := RandomSalt + 1.
   282     ].
   280     ].
   283     hash nextPut:RandomSalt.
   281 
   284     hash nextPutAll:Time microsecondClockValue asLargeInteger digitBytes. 
   282     hash := MD5Stream new.
   285     hash nextPutAll:OperatingSystem getProcessId asLargeInteger digitBytes. 
   283     hash 
   286     hash nextPutAll:(ObjectMemory addressOf:(Object new)) asLargeInteger digitBytes. 
   284         nextPut:RandomSalt;
   287     hash nextPutAll:(ObjectMemory oldSpaceUsed) asLargeInteger digitBytes. 
   285         nextPut:Time microsecondClockValue; 
   288     hash nextPutAll:(ObjectMemory newSpaceUsed) asLargeInteger digitBytes. 
   286         nextPut:OperatingSystem getProcessId; 
       
   287         nextPut:(ObjectMemory addressOf:Object new); 
       
   288         nextPut:ObjectMemory oldSpaceUsed; 
       
   289         nextPut:ObjectMemory newSpaceUsed. 
   289     [
   290     [
   290         hash nextPutAll:(OperatingSystem getCPUCycleCount) asLargeInteger digitBytes. 
   291         hash nextPut:OperatingSystem getCPUCycleCount. 
   291     ] on:PrimitiveFailure do:[].
   292     ] on:PrimitiveFailure do:[].
   292 
   293 
   293     "/ any other cheap sources of entropy?
   294     "/ any other cheap sources of entropy?
   294 
   295 
   295     "/ I think there is no problem in that MD5 is not a secure hash algo here - the idea is to shuffle the bits around a bit
   296     "/ I think there is no problem in that MD5 is not a secure hash algo here - the idea is to shuffle the bits around a bit
   755 ! !
   756 ! !
   756 
   757 
   757 !Random class methodsFor:'documentation'!
   758 !Random class methodsFor:'documentation'!
   758 
   759 
   759 version
   760 version
   760     ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.56 2014-10-02 15:36:18 cg Exp $'
   761     ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.57 2014-10-02 17:56:20 stefan Exp $'
   761 !
   762 !
   762 
   763 
   763 version_CVS
   764 version_CVS
   764     ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.56 2014-10-02 15:36:18 cg Exp $'
   765     ^ '$Header: /cvs/stx/stx/libbasic2/Random.st,v 1.57 2014-10-02 17:56:20 stefan Exp $'
   765 ! !
   766 ! !
   766 
   767