Random Number Tables
Collaboration diagram for Random Number Tables:


This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.

Files

file  rand.c
These are our tables of random numbers.

Macros

#define BN_RAND_TABSIZE   4096
A supply of fast pseudo-random numbers from table in bn/rand.c. The values are in the open interval (i.e. exclusive) of 0.0 to 1.0 range with a period of 4096. More...

#define BN_RANDSEED(_i, _seed)   _i = ((unsigned)_seed) % BN_RAND_TABSIZE

#define BN_RANDOM(_i)   bn_rand_table[ _i = (_i+1) % BN_RAND_TABSIZE ]

#define BN_RANDHALF(_i)   (bn_rand_table[ _i = (_i+1) % BN_RAND_TABSIZE ]-0.5)

#define BN_RANDHALF_INIT(_p)   _p = bn_rand_table

#define BN_RANDHALFTABSIZE   16535 /* Powers of two give streaking */

#define bn_rand_half(_p)

#define bn_rand_init(_p, _seed)

#define bn_rand0to1(_q)   (bn_rand_half(_q)+0.5)

#define BN_SINTABSIZE   2048

#define bn_tab_sin(_a)

Functions

void bn_mathtab_constant (void)
For benchmarking purposes, make the random number table predictable. Setting to all zeros keeps dithered values at their original values. More...

double bn_randmt (void)
Mersenne Twister random number generation as defined by MT19937. More...

void bn_randmt_seed (unsigned long seed)

Variables

const float bn_rand_table [BN_RAND_TABSIZE]

int bn_randhalftabsize

float bn_rand_halftab [BN_RANDHALFTABSIZE]

const float bn_sin_table [BN_SINTABSIZE]

const float bn_rand_table [BN_RAND_TABSIZE]

const float bn_sin_table [BN_SINTABSIZE]

int bn_randhalftabsize = BN_RANDHALFTABSIZE

float bn_rand_halftab [BN_RANDHALFTABSIZE]

float bn_rand_poison_ []

Macro Definition Documentation

 #define BN_RAND_TABSIZE   4096

A supply of fast pseudo-random numbers from table in bn/rand.c. The values are in the open interval (i.e. exclusive) of 0.0 to 1.0 range with a period of 4096.

Usage:
1 unsigned idx;
2 float f;
3
4 BN_RANDSEED(idx, integer_seed);
5
6 while (NEED_MORE_RAND_NUMBERS) {
7 f = BN_RANDOM(idx);
8 }

Note that the values from bn_rand_half() become all 0.0 when the benchmark flag is set (bn_rand_halftab is set to all 0's). The numbers from bn_rand_table do not change, because the procedural noise would cease to exist.

Definition at line 58 of file rand.h.

Referenced by bn_noise_init().

Definition at line 59 of file rand.h.

 #define BN_RANDSEED ( _i, _seed ) _i = ((unsigned)_seed) % BN_RAND_TABSIZE

Definition at line 60 of file rand.h.

Referenced by bn_noise_init(), and rtrans_setup().

 #define BN_RANDOM ( _i ) bn_rand_table[ _i = (_i+1) % BN_RAND_TABSIZE ]

BN_RANDOM always gives numbers between the open interval 0.0 to 1.0

Definition at line 73 of file rand.h.

Referenced by bn_cmd_random(), bn_noise_init(), and rtrans_render().

 #define BN_RANDHALF ( _i ) (bn_rand_table[ _i = (_i+1) % BN_RAND_TABSIZE ]-0.5)

BN_RANDHALF always gives numbers between the open interval -0.5 and 0.5

Definition at line 76 of file rand.h.

 #define BN_RANDHALF_INIT ( _p ) _p = bn_rand_table

Definition at line 77 of file rand.h.

 #define BN_RANDHALFTABSIZE   16535 /* Powers of two give streaking */

Definition at line 79 of file rand.h.

 #define bn_rand_half ( _p )
Value:
(_p) < bn_rand_halftab) ? \
*((_p) = bn_rand_halftab) : *(_p))
float bn_rand_halftab[BN_RANDHALFTABSIZE]
Definition: rand.c:1240
int bn_randhalftabsize
Definition: rand.c:1238

random numbers between the closed interval -0.5 to 0.5 inclusive, except when benchmark flag is set, when this becomes a constant 0.0

Parameters
 _p float pointer type initialized by bn_rand_init()

Definition at line 97 of file rand.h.

Referenced by wood_turb().

 #define bn_rand_init ( _p, _seed )
Value:
(_p) = &bn_rand_halftab[ \
(int)(\
(bn_rand_halftab[(_seed)%bn_randhalftabsize] + 0.5) * \
float bn_rand_halftab[BN_RANDHALFTABSIZE]
Definition: rand.c:1240
int bn_randhalftabsize
Definition: rand.c:1238

initialize the seed for the large random number table (halftab)

Parameters
 _p float pointer to be initialized, used for bn_rand0to1() and bn_rand_half() _seed Integer SEED for offset in the table.

Definition at line 110 of file rand.h.

Referenced by data2uchar(), and rt_init_resource().

 #define bn_rand0to1 ( _q ) (bn_rand_half(_q)+0.5)

random numbers in the closed interval 0.0 to 1.0 range (inclusive) except when benchmarking, when this is always 0.5

Parameters
 _q float pointer type initialized by bn_rand_init()

Definition at line 123 of file rand.h.

Referenced by data2uchar(), star_render(), wood_setup(), and wood_setup_2().

 #define BN_SINTABSIZE   2048

Definition at line 125 of file rand.h.

 #define bn_tab_sin ( _a )
Value:
(((_a) > 0) ? \
(bn_sin_table[(int)((0.5+ (_a)*(BN_SINTABSIZE / M_2PI)))&(BN_SINTABSIZE-1)]) :\
(-bn_sin_table[(int)((0.5- (_a)*(BN_SINTABSIZE / M_2PI)))&(BN_SINTABSIZE-1)]))
#define BN_SINTABSIZE
Definition: rand.h:125
const float bn_sin_table[BN_SINTABSIZE]
Definition: rand.c:723

Definition at line 127 of file rand.h.

Referenced by cloud_texture().

Function Documentation

 void bn_mathtab_constant ( void )

For benchmarking purposes, make the random number table predictable. Setting to all zeros keeps dithered values at their original values.

Definition at line 3619 of file rand.c.

References bn_rand_halftab.

 double bn_randmt ( void )

Mersenne Twister random number generation as defined by MT19937.

Generates one pseudorandom real number (double) which is uniformly distributed on [0, 1]-interval, for each call.

Usage:
1 double d;
2
3 bn_randmt_seed(integer_seed);
4
5 while (NEED_MORE_RAND_NUMBERS) {
6 d = bn_randmt();
7 }

Definition at line 149 of file randmt.c.

References bn_randmt_state().

Referenced by chull3d_make_shuffle().

Here is the call graph for this function:

 void bn_randmt_seed ( unsigned long seed )

Definition at line 144 of file randmt.c.

References bn_randmt_state_seed().

Referenced by bn_randmt_state().

Here is the call graph for this function:

Variable Documentation

 const float bn_rand_table[BN_RAND_TABSIZE]

This is our table of random numbers. Rather than calling drand48() or random() or rand() we just pick numbers out of this table. This table has 4096 unique entries with floating point values ranging from the open interval (i.e. exclusive) 0.0 to 1.0 range.

There are convenience macros for access in the bn.h header.

Definition at line 36 of file rand.c.

 int bn_randhalftabsize

Definition at line 1238 of file rand.c.

 float bn_rand_halftab[BN_RANDHALFTABSIZE]

The actual table of random floating point numbers with values in the closed interval (i.e. inclusive) -0.5 to +0.5 range.

For benchmarking purposes, this table is zeroed.

Definition at line 1240 of file rand.c.

 const float bn_sin_table[BN_SINTABSIZE]

table of floating point sine values in the closed (i.e. inclusive) interval -1.0 to 1.0 range.

Definition at line 723 of file rand.c.

 const float bn_rand_table[BN_RAND_TABSIZE]

This is our table of random numbers. Rather than calling drand48() or random() or rand() we just pick numbers out of this table. This table has 4096 unique entries with floating point values ranging from the open interval (i.e. exclusive) 0.0 to 1.0 range.

There are convenience macros for access in the bn.h header.

Definition at line 36 of file rand.c.

 const float bn_sin_table[BN_SINTABSIZE]

table of floating point sine values in the closed (i.e. inclusive) interval -1.0 to 1.0 range.

Definition at line 723 of file rand.c.

 int bn_randhalftabsize = BN_RANDHALFTABSIZE

Definition at line 1238 of file rand.c.

 float bn_rand_halftab[BN_RANDHALFTABSIZE]

The actual table of random floating point numbers with values in the closed interval (i.e. inclusive) -0.5 to +0.5 range.

For benchmarking purposes, this table is zeroed.

Definition at line 1240 of file rand.c.

Referenced by bn_mathtab_constant().

 float bn_rand_poison_[]
Initial value:
= {
9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f,
9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f,
9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f,
9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f, 9e20f
}

Immediately after the random number table, some "poison" floating point numbers, intended to cause noticeable difficulties if these are used.

Definition at line 3611 of file rand.c.