eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RandomParkMiller':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: RandomParkMiller


Inheritance:

   Object
   |
   +--RandomParkMiller

Package:
stx:libbasic2
Category:
Magnitude-Numbers-Random
Version:
rev: 1.16 date: 2023/05/29 15:50:24
user: cg
file: RandomParkMiller.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


WARNING: this generator should NOT be used for cryptographic work.

NO WARRANTY

Another pseudo-random number generator

The ParkMiller random generator (although better than the old Random), is not recommended 
when a high quality random is required (for example, for cryptographic work). 
Applications should use either the OS-random generator or a LaggedFibonacci generator.
This is because the random values provided by the Park-Miller generator are double precision 
floating point numbers which have up to 53 significant bits. Since only the first 31 bits 
of their mantissa are known to have good random properties, the behavior of the remaining 
22 bits is undefined. 
In particular, bit aliasing occurs during the calculation of the next random value, 
and bit 22 of the mantissa is always 1.

Please read:
    Standard reference by Park and Miller in 
        'Random Number Generators: Good Ones Are Hard to Find',
    Comm. ACM, 31:1192-1201, 1988.

testing

|r| r := self new. (1 to:10) collect:[:i | r next] -> should be #( 0.1492432697 0.3316330217 0.7561964480 0.3937015400 0.9417831814 0.5499291939 0.6599625962 0.9913545591 0.6960744326 0.9229878997 #)

Class protocol:

initialization
o  initialize
magic constant

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables


Instance protocol:

accessing-reading
o  nextBoolean
This method generates a boolean

o  nextInteger
This method generates random instances of Integer in the interval 0 to 16r7FFFFFFF.

initialization
o  initialize
Set a reasonable Park-Miller starting seed

o  seed: anInteger

private
o  peek
This method answers the next random number that will be generated as a Float in the range [0..1).
It answers the same value for all successive message sends.

o  peekInteger
This method generates random instances of Integer in the interval 0 to 16r7FFFFFFF. This method does NOT update the seed; repeated sends answer the same value. The algorithm is described in detail in 'Random Number Generators: Good Ones Are Hard to Find' by Stephen K. Park and Keith W. Miller, (Comm. Asso. Comp. Mach., 31(10):1192--1201, 1988).

reading
o  next
This method generates random instances of Float in the interval 0.0 to 1.0



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Tue, 03 Dec 2024 17:28:15 GMT