RandomKISS.st
changeset 3364 386f1893c6ba
parent 3356 abf44c625c74
child 3365 2df5a041ea67
equal deleted inserted replaced
3363:661537bcd48e 3364:386f1893c6ba
   300     "generates the next integer in 0..FFFFFFFF"
   300     "generates the next integer in 0..FFFFFFFF"
   301 
   301 
   302     |t|
   302     |t|
   303 
   303 
   304     "/ Linear Congruencegenerator
   304     "/ Linear Congruencegenerator
   305     x := (314527869 * x) + 1234567.
   305     x := (69069 * x) + 12345.
   306     x := x bitAnd:16rFFFFFFFF.
   306     x := x bitAnd:16rFFFFFFFF.
   307 
   307 
   308     "/ Xorshift
   308     "/ Xorshift
   309     y := y bitXor:(y << 22).
   309     y := y bitXor:(y << 13).
   310     y := y bitXor:(y >> 17).
   310     y := y bitXor:(y >> 17).
   311     y := y bitXor:(y << 5).
   311     y := y bitXor:(y << 5).
   312     y := y bitAnd:16rFFFFFFFF.
   312     y := y bitAnd:16rFFFFFFFF.
   313 
   313 
   314     "/ Multiply-with-carry
   314     "/ Multiply-with-carry
   315     t := (4294584393 * z) + c.
   315     t := (698769069 * z) + c.
   316     c := t >> 32.
   316     c := t >> 32.
   317     z := t bitAnd:16rFFFFFFFF.
   317     z := t bitAnd:16rFFFFFFFF.
   318 
   318 
   319     ^ (x + y + z) bitAnd:16rFFFFFFFF
   319     ^ (x + y + z) bitAnd:16rFFFFFFFF
   320 ! !
   320 ! !
   321 
   321 
   322 !RandomKISS class methodsFor:'documentation'!
   322 !RandomKISS class methodsFor:'documentation'!
   323 
   323 
   324 version
   324 version
   325     ^ '$Header: /cvs/stx/stx/libbasic2/RandomKISS.st,v 1.1 2014-10-01 13:18:07 cg Exp $'
   325     ^ '$Header: /cvs/stx/stx/libbasic2/RandomKISS.st,v 1.2 2014-10-01 13:23:26 cg Exp $'
   326 !
   326 !
   327 
   327 
   328 version_CVS
   328 version_CVS
   329     ^ '$Header: /cvs/stx/stx/libbasic2/RandomKISS.st,v 1.1 2014-10-01 13:18:07 cg Exp $'
   329     ^ '$Header: /cvs/stx/stx/libbasic2/RandomKISS.st,v 1.2 2014-10-01 13:23:26 cg Exp $'
   330 ! !
   330 ! !
   331 
   331