Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

random.c File Reference

#include "ruby.h"
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

Go to the source code of this file.

Defines

#define N   624
#define M   397
#define MATRIX_A   0x9908b0dfUL
#define UMASK   0x80000000UL
#define LMASK   0x7fffffffUL
#define MIXBITS(u, v)   ( ((u) & UMASK) | ((v) & LMASK) )
#define TWIST(u, v)   ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
#define BIG_GET32(big, i)   (((BDIGIT *)(big)->digits)[i])
#define BIG_SET32(big, i, d)   (((BDIGIT *)(big)->digits)[i] = (d))

Functions

void init_genrand (unsigned long s)
void init_by_array (unsigned long init_key[], int key_length)
void next_state ()
unsigned long genrand_int32 (void)
double genrand_real (void)
VALUE rand_init (VALUE vseed)
VALUE random_seed ()
VALUE rb_f_srand (int argc, VALUE *argv, VALUE obj)
unsigned long make_mask (unsigned long x)
unsigned long limited_rand (unsigned long limit)
VALUE limited_big_rand (struct RBignum *limit)
VALUE rb_f_rand (int argc, VALUE *argv, VALUE obj)
void Init_Random ()

Variables

unsigned long state [N]
int left = 1
int initf = 0
unsigned long * next
int first = 1
VALUE saved_seed = INT2FIX(0)


Define Documentation

#define BIG_GET32 big,
 )     (((BDIGIT *)(big)->digits)[i])
 

Referenced by limited_big_rand().

#define BIG_SET32 big,
i,
 )     (((BDIGIT *)(big)->digits)[i] = (d))
 

Referenced by limited_big_rand().

#define LMASK   0x7fffffffUL
 

Definition at line 68 of file random.c.

#define M   397
 

Definition at line 65 of file random.c.

Referenced by next_state().

#define MATRIX_A   0x9908b0dfUL
 

Definition at line 66 of file random.c.

#define MIXBITS u,
 )     ( ((u) & UMASK) | ((v) & LMASK) )
 

Definition at line 69 of file random.c.

#define N   624
 

Definition at line 64 of file random.c.

Referenced by init_by_array(), init_genrand(), and next_state().

#define TWIST u,
 )     ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
 

Definition at line 70 of file random.c.

Referenced by next_state().

#define UMASK   0x80000000UL
 

Definition at line 67 of file random.c.


Function Documentation

unsigned long genrand_int32 void   )  [static]
 

Definition at line 150 of file random.c.

References left, next, and next_state().

Referenced by genrand_real(), limited_big_rand(), and limited_rand().

double genrand_real void   )  [static]
 

Definition at line 168 of file random.c.

References genrand_int32().

Referenced by rb_f_rand().

void init_by_array unsigned long  init_key[],
int  key_length
[static]
 

Definition at line 100 of file random.c.

References init_genrand(), initf, left, N, and state.

Referenced by rand_init().

void init_genrand unsigned long  s  )  [static]
 

Definition at line 79 of file random.c.

References initf, left, N, and state.

Referenced by init_by_array(), next_state(), and rand_init().

void Init_Random void   ) 
 

Definition at line 498 of file random.c.

References rb_define_global_function(), rb_f_rand(), rb_f_srand(), rb_global_variable(), and saved_seed.

Referenced by rb_call_inits().

VALUE limited_big_rand struct RBignum limit  )  [static]
 

Definition at line 374 of file random.c.

References BIG_GET32, BIG_SET32, genrand_int32(), RBignum::len, make_mask(), rb_big_clone(), rb_big_norm(), SIZEOF_BDIGITS, and VALUE.

Referenced by rb_f_rand().

unsigned long limited_rand unsigned long  limit  )  [static]
 

Definition at line 354 of file random.c.

References genrand_int32(), make_mask(), and SIZEOF_LONG.

Referenced by rb_f_rand().

unsigned long make_mask unsigned long  x  )  [static]
 

Definition at line 340 of file random.c.

Referenced by limited_big_rand(), and limited_rand().

void next_state  )  [static]
 

Definition at line 127 of file random.c.

References init_genrand(), initf, left, M, N, next, state, and TWIST.

Referenced by genrand_int32().

VALUE rand_init VALUE  vseed  )  [static]
 

Definition at line 196 of file random.c.

References ALLOC_N, BDIGIT, first, FIX2ULONG, FIXNUM_P, free, init_by_array(), init_genrand(), rb_eTypeError, rb_obj_classname(), rb_raise(), rb_to_int(), RBIGNUM, saved_seed, SIZEOF_BDIGITS, T_BIGNUM, T_FIXNUM, TYPE, and VALUE.

Referenced by rb_f_rand(), and rb_f_srand().

VALUE random_seed  )  [static]
 

Definition at line 256 of file random.c.

References ALLOC_N, BDIGIT, NEWOBJ, OBJSETUP, rb_big_norm(), rb_cBignum, S_ISCHR, SIZEOF_BDIGITS, T_BIGNUM, timeval::tv_sec, timeval::tv_usec, and VALUE.

Referenced by rb_f_rand(), and rb_f_srand().

VALUE rb_f_rand int  argc,
VALUE argv,
VALUE  obj
[static]
 

Definition at line 439 of file random.c.

References first, FIX2LONG, FIXNUM_P, genrand_real(), INT2FIX, limited_big_rand(), limited_rand(), LONG2NUM, LONG_MIN, rand_init(), random_seed(), rb_big_clone(), rb_big_minus(), rb_dbl2big(), rb_float_new(), rb_Integer(), rb_scan_args(), RFLOAT, T_BIGNUM, T_FIXNUM, T_FLOAT, T_NIL, TYPE, and VALUE.

Referenced by Init_Random().

VALUE rb_f_srand int  argc,
VALUE argv,
VALUE  obj
[static]
 

Definition at line 323 of file random.c.

References rand_init(), random_seed(), rb_scan_args(), rb_secure(), and VALUE.

Referenced by Init_Random().


Variable Documentation

int first = 1 [static]
 

Definition at line 192 of file random.c.

Referenced by rand_init(), and rb_f_rand().

int initf = 0 [static]
 

Definition at line 74 of file random.c.

Referenced by init_by_array(), init_genrand(), and next_state().

int left = 1 [static]
 

Definition at line 73 of file random.c.

Referenced by genrand_int32(), init_by_array(), init_genrand(), and next_state().

unsigned long* next [static]
 

Definition at line 75 of file random.c.

Referenced by genrand_int32(), and next_state().

VALUE saved_seed = INT2FIX(0) [static]
 

Definition at line 193 of file random.c.

Referenced by Init_Random(), and rand_init().

unsigned long state[N] [static]
 

Definition at line 72 of file random.c.

Referenced by init_by_array(), init_genrand(), and next_state().


Generated on Wed Jan 18 23:32:10 2006 for Ruby by doxygen 1.3.5