Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

subtractive_rng Class Reference

#include <stl_function.h>

Inheritance diagram for subtractive_rng:

Inheritance graph
[legend]
Collaboration diagram for subtractive_rng:

Collaboration graph
[legend]
List of all members.

Public Methods

unsigned int operator() (unsigned int limit)
void initialize (unsigned int seed)
 subtractive_rng (unsigned int seed)
 subtractive_rng ()

Private Attributes

unsigned int table [55]
size_t index1
size_t index2

Constructor & Destructor Documentation

subtractive_rng::subtractive_rng unsigned int    seed [inline]
 

Definition at line 400 of file stl_function.h.

References initialize.

00400 { initialize(seed); }

subtractive_rng::subtractive_rng   [inline]
 

Definition at line 401 of file stl_function.h.

References initialize.

00401 { initialize(161803398u); }


Member Function Documentation

void subtractive_rng::initialize unsigned int    seed [inline]
 

Definition at line 381 of file stl_function.h.

References index1, index2, and table.

Referenced by subtractive_rng.

00382   {
00383     unsigned int k = 1;
00384     table[54] = seed;
00385     size_t i;
00386     for (i = 0; i < 54; i++) {
00387         size_t ii = (21 * (i + 1) % 55) - 1;
00388         table[ii] = k;
00389         k = seed - k;
00390         seed = table[ii];
00391     }
00392     for (int loop = 0; loop < 4; loop++) {
00393         for (i = 0; i < 55; i++)
00394             table[i] = table[i] - table[(1 + i + 30) % 55];
00395     }
00396     index1 = 0;
00397     index2 = 31;
00398   }

unsigned int subtractive_rng::operator() unsigned int    limit [inline]
 

Definition at line 374 of file stl_function.h.

References index1, index2, and table.

00374                                               {
00375     index1 = (index1 + 1) % 55;
00376     index2 = (index2 + 1) % 55;
00377     table[index1] = table[index1] - table[index2];
00378     return table[index1] % limit;
00379   }


Member Data Documentation

size_t subtractive_rng::index1 [private]
 

Definition at line 371 of file stl_function.h.

Referenced by initialize, and operator().

size_t subtractive_rng::index2 [private]
 

Definition at line 372 of file stl_function.h.

Referenced by initialize, and operator().

unsigned int subtractive_rng::table[55] [private]
 

Definition at line 370 of file stl_function.h.

Referenced by initialize, and operator().


The documentation for this class was generated from the following file:
logo OpenMask

Documentation generated on Thu May 2 15:03:46 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001