eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RandomTT800':

Home

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

Class: RandomTT800


Inheritance:

   Object
   |
   +--RandomTT800

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

Description:


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

NO WARRANTY

Slightly adapted Squeak code for fileIn into ST/X.
The original comment was:


A pseudo-random number generator; see below for references.
This generator is much slower than Squeak's Random class.
It automatically seeds itself based on the millisecond clock.

Using the generator:

        randy := RandomTT800 new.
        randy seed: anInteger. 'optional; never use zero'
        aRandom := randy next.

Example (InspectIt):

        | r |
        r := RandomTT800 new.
        (1 to: 50) collect: [ :n | r next ].

===================================================================

Originally a C-program for TT800 : July 8th 1996 Version
by M. Matsumoto, email: matumoto@math.keio.ac.jp

Generates one pseudorandom number with double precision which is uniformly distributed 
on [0,1]-interval for each call.  One may choose any initial 25 seeds except all zeros.

See: ACM Transactions on Modelling and Computer Simulation,
Vol. 4, No. 3, 1994, pages 254-266.

ABSTRACT 

The twisted GFSR generators proposed in a previous article have a defect in k-distribution for k larger 
than the order of recurrence. 
In this follow up article, we introduce and analyze a new TGFSR variant having better k-distribution property. 
We provide an efficient algorithm to obtain the order of equidistribution, together with a tight upper bound 
on the order. 
We discuss a method to search for generators attaining this bound, and we list some of these such generators. 
The upper bound turns out to be (sometimes far) less than the maximum order of equidistribution for a generator 
of that period length, but far more than that for a GFSR with a working are of the same size.

Previous paper:

ACM Transactions on Modeling and Computer Simulation 
Volume 2 , Issue 3 (1992) Pages 179-194 
Twisted GFSR generators 
Makoto Matsumoto, and Yoshiharu Kurita 

ABSTRACT 

The generalized feed back shift register (GFSR) algorithm suggested by Lewis and Payne is a widely used pseudorandom number generator, but has the following serious drawbacks: (1) an initialization scheme to assure higher order equidistribution is involved and is time consuming; (2) each bit of the
generated words constitutes an m-sequence based on a primitive trinomials, which shows poor randomness with respect to weight distribution; (3) a large working area is necessary; (4) the period of sequence is far shorter than the theoretical upper bound. This paper presents the twisted GFSR (TGFSR) algorithm, a slightly but essentially modified version of the GFSR, which solves all the above problems without loss of merit. Some practical TGFSR generators were implemented and passed strict empirical tests. These new generators are most suitable for simulation of a large distributive system, which requires a number of mutually independent pseudorandom number generators with compact size.

copyright

PLEASE READ THE FOLLOWING NOTICE AND DISCLAIMER CAREFULLY BEFORE DOWNLOADING THIS SOFTWARE. BY DOWNLOADING THIS SOFTWARE YOU ARE AGREEING TO BE BOUND BY THESE TERMS. IF YOU DO NOT AGREE TO THE TERMS, DO NOT DOWNLOAD. This software (Software), provided by IBM Corporation, may contain, or be derived from, code provided by Apple Computer, Inc., and is provided subject to the provisions of the Apple Computer, Inc. Software License for the SQUEAK Smalltalk System which can be viewed at http://www.squeak.org/license.html. This Software is provided AS IS, and IBM Corporation DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IBM DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED IN THE SOFTWARE WILL MEET THE USERS' REQUIREMENTS, THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT DEFECTS IN THE SOFTWARE WILL BE CORRECTED. UNDER NO CIRCUMSTANCES SHALL IBM CORPORATION BE LIABLE FOR INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES ARISING FROM OR RELATING TO USE OF THIS SOFTWARE. The user of this Software agrees to indemnify and hold IBM Corporation harmless from any and all damages, liabilities, costs and expenses (including attorney's fees) incurred by IBM Corporation as a result of any claim, proceeding or judgment to the extent it arises out of or is connected in any manner with the operation, use, distribution or modification of the Software, or the combination of the Software or modified Software with other programs.

LICENSE

see copyright

TT800OriginalCVersion

From: http://random.mat.sbg.ac.at/ftp/pub/data/tt800.c /* A C-program for TT800 : July 8th 1996 Version */ /* by M. Matsumoto, email: matumoto@math.keio.ac.jp */ /* genrand() generate one pseudorandom number with double precision */ /* which is uniformly distributed on [0,1]-interval */ /* for each call. One may choose any initial 25 seeds */ /* except all zeros. */ /* See: ACM Transactions on Modelling and Computer Simulation, */ /* Vol. 4, No. 3, 1994, pages 254-266. */ /* ABSTRACT The twisted GFSR generators proposed in a previous article have a defect in k-distribution for k larger than the order of recurrence. In this follow up article, we introduce and analyze a new TGFSR variant having better k-distribution property. We provide an efficient algorithm to obtain the order of equidistribution, together with a tight upper bound on the order. We discuss a method to search for generators attaining this bound, and we list some of these such generators. The upper bound turns out to be (sometimes far) less than the maximum order of equidistribution for a generator of that period length, but far more than that for a GFSR with a working are of the same size. */ #include <stdio.h> #define N 25 #define M 7 double genrand() { unsigned long y; static int k = 0; static unsigned long x[N]={ /* initial 25 seeds, change as you wish */ 0x95f24dab, 0x0b685215, 0xe76ccae7, 0xaf3ec239, 0x715fad23, 0x24a590ad, 0x69e4b5ef, 0xbf456141, 0x96bc1b7b, 0xa7bdf825, 0xc1de75b7, 0x8858a9c9, 0x2da87693, 0xb657f9dd, 0xffdc8a9f, 0x8121da71, 0x8b823ecb, 0x885d05f5, 0x4e20cd47, 0x5a9ad5d9, 0x512c0c03, 0xea857ccd, 0x4cc1d30f, 0x8891a8a1, 0xa6b7aadb }; static unsigned long mag01[2]={ 0x0, 0x8ebfd028 /* this is magic vector `a', don't change */ }; if (k==N) { /* generate N words at one time */ int kk; for (kk=0;kk<N-M;kk++) { x[kk] = x[kk+M] ^ (x[kk] >> 1) ^ mag01[x[kk] % 2]; } for (; kk<N;kk++) { x[kk] = x[kk+(M-N)] ^ (x[kk] >> 1) ^ mag01[x[kk] % 2]; } k=0; } y = x[k]; y ^= (y << 7) & 0x2b5b2500; /* s and b, magic vectors */ y ^= (y << 15) & 0xdb8b0000; /* t and c, magic vectors */ y &= 0xffffffff; /* you may delete this line if word size = 32 */ /* the following line was added by Makoto Matsumoto in the 1996 version to improve lower bit's corellation. Delete this line to o use the code published in 1994. */ y ^= (y >> 16); /* added to the 1994 version */ k++; return( (double) y / (unsigned long) 0xffffffff); }

Class protocol:

initialization
o  initialSeeds
initial 25 seeds, change as you wish. (there must be N seeds)

o  originalSeeds
original initial 25 seeds. DO NOT CHANGE

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

testing
o  bucketTest1
Answers an array with 50 elements each of which should hold an integer near the value 1000,
the closer the better.

Usage example(s):

RandomTT800 bucketTest1 inspect 

o  firstInteger: s
Answers an array with the first 's' raw integer elements generated by the RNG using the original seeds.
Intended for testing only.

Usage example(s):

RandomTT800 firstInteger: 50 

o  theItsCompletelyBrokenTest
Test to see if generator is answering what it should.
Assumes that the initial seeds are what is given in the original version.
If this fails something is badly wrong; do not use this generator.

Usage example(s):

RandomTT800 theItsCompletelyBrokenTest 


Instance protocol:

initialization
o  initialize
x := self class initialSeeds. (Done in #seed:)

o  seed: anInteger

o  setSeeds: anArray
Used only by class methods for testing.

random numbers
o  nextBoolean
Answer the next boolean

o  nextInteger
Answer the next random number in its raw integer form

reading
o  next
Answer the next random number as a float in the range [0.0,1.0)


Examples:


    | r |
    r := RandomTT800 new.
    (1 to: 50) collect: [ :n | r next ].


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 15:47:10 GMT