Random methodDictionary do: [:each | Transcript show: each methodSourceString; cr]. !
Standard input is empty
between: low and: high [ "Return a random integer between low and high." <category: 'basic'> | i range | range := high - low + 1. i := (self next * range) truncated. ^i + low ] chiSquare [ "Compute the chi-square of the random that this class generates." "the previous algorithm's chi-square was 93.4" <category: 'testing'> ^self chiSquare: 1000 range: 100 ] chiSquare: n range: r [ "Return the chi-square deduced from calculating n random numbers in the 0..r range." <category: 'testing'> | f t seed | seed := 0.1234567. f := Array new: r + 1. 1 to: r + 1 do: [:i | f at: i put: 0]. n timesRepeat: [seed := (seed + Float pi) squared squared fractionPart. t := (seed * r) truncated. f at: t + 1 put: (f at: t + 1) + 1]. t := 0. 1 to: r do: [:i | t := t + (f at: i) squared]. ^r asFloat * t / n - n ] nextPut: value [ <category: 'basic'> self shouldNotImplement ] atEnd [ "This stream never ends. Always answer false." <category: 'basic'> ^false ] setSeed [ "Private - Set a random number seed." <category: 'private'> seed := Time primSecondClock bitXor: Time millisecondClock. seed := seed + (Time primNanosecondClock \\ 1000000). seed := (seed / 4194303.0) fractionPart. self next. self next ] seed: aFloat [ "Private - Set the random number seed to aFloat. Ensure decent results even when integers are passed" <category: 'private'> seed := (aFloat / 100000.0 + aFloat) fractionPart. self next. self next ] next [ "Return the next random number in the sequence." "Found on an obscure Japanese manual. Turns out to be good!" <category: 'basic'> ^seed := (seed + Float pi) squared squared fractionPart ]