
Class: RandomGNUSmalltalk
Object

+Stream

+Random

+RandomGNUSmalltalk
 Package:
 stx:libbasic2
 Category:
 MagnitudeNumbersRandom
 Version:
 rev:
1.2
date: 2018/03/02 16:08:05
 user: cg
 file: RandomGNUSmalltalk.st directory: libbasic2
 module: stx stcclassLibrary: libbasic2
 Author:
 Steve Byrne
 Claus Gittinger
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
=======================================================================================
DO NOT USE THIS GENERATOR FOR CRYPTOGRAPHY OR OTHER SECURITY RELATED WORK,
because linear congruential generators are predictable and can be broken easily!
Smalltalk/X includes a better generator named RandomGenerator,
which uses the best available generator of the system
(either OSrandom, /dev/random or as a less dangerous fallback, an RC4based random generator).
Please use that one.
=======================================================================================
A simple random numbers  thanks to Steves GNU Smalltalk
This implements a linear congruential maximum period random number generator
which passes the spectral test for randomness for dimensions 2 3 4 5 6.
Notice: although being included here,
this file is NOT covered by the ST/X license, but by
the FSF copyLeft (see copyright method).
You can redistribute it under the terms stated there ...
Also, the price you pay for ST/X does not include a charge for
this file  it has to be considered as a separate piece of
software, which can be copied and given away without any
restriction from my (CG) side.
http://www0.cs.ucl.ac.uk/staff/d.jones/GoodPracticeRNG.pdf
RandomTT800

a
new
random
generator
RandomParkMiller

another
new
random
generator
accessingreading

maxInteger


next

return the next random number in the range ]0..1[

nextBoolean

return true or false by random

nextInteger

return the next integral random number,
in the range 0 .. modulus (which is less than 16r3FFFFFFF).
From Sedgewick's 'Algorithms', based on Lehmer's method.
Take care, this returns an even number after each odd number!
private

setSeed: seedValue

set the initial seed and intialite the PRNG parameters.
These numbers implement a maximum period generator which passes
the spectral test for randomness for dimensions 2 3 4 5 6 and
the product does not overflow 2 raisedTo:29.
These numbers are carefully choosen, so don't change them,
unless you know what you are doing!

step

compute the next random integer
rnd
rnd := RandomGNUSmalltalk new.
10 timesRepeat:[
Transcript showCR:(rnd next)
]

rolling a dice:
rnd
rnd := RandomGNUSmalltalk new.
10 timesRepeat:[
Transcript showCR:(rnd nextIntegerBetween:1 and:6)
]

