SFMT.cpp File Reference

#include <string.h>
#include "error.h"
#include "SFMT.h"
#include "SFMT-params.h"

Go to the source code of this file.

Classes

struct  W128_T

Typedefs

typedef struct W128_T w128_t

Functions

static int idxof (int i)
static void rshift128 (w128_t *out, w128_t const *in, int shift)
static void lshift128 (w128_t *out, w128_t const *in, int shift)
static void gen_rand_all (void)
static void gen_rand_array (w128_t *array, int size)
static uint32_t func1 (uint32_t x)
static uint32_t func2 (uint32_t x)
static void period_certification (void)
static void do_recursion (w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d)
const char * get_idstring (void)
int get_min_array_size32 (void)
int get_min_array_size64 (void)
uint32_t gen_rand32 (void)
uint64_t gen_rand64 (void)
void fill_array32 (uint32_t *array, int size)
void fill_array64 (uint64_t *array, int size)
void init_gen_rand (uint32_t seed)
void init_by_array (uint32_t *init_key, int key_length)

Variables

static w128_t sfmt [N]
static uint32_t * psfmt32 = &sfmt[0].u[0]
static uint64_t * psfmt64 = (uint64_t *)&sfmt[0].u[0]
static int idx
static int initialized = 0
static uint32_t parity [4] = {PARITY1, PARITY2, PARITY3, PARITY4}


Typedef Documentation

typedef struct W128_T w128_t

128-bit data type

Definition at line 63 of file SFMT.cpp.


Function Documentation

static void do_recursion ( w128_t r,
w128_t a,
w128_t b,
w128_t c,
w128_t d 
) [inline, static]

This function represents the recursion formula.

Parameters:
r output
a a 128-bit part of the internal state array
b a 128-bit part of the internal state array
c a 128-bit part of the internal state array
d a 128-bit part of the internal state array

Definition at line 227 of file SFMT.cpp.

References lshift128(), MSK1, MSK2, MSK3, MSK4, rshift128(), SL1, SL2, SR1, SR2, and W128_T::u.

Referenced by gen_rand_all(), and gen_rand_array().

void fill_array32 ( uint32_t *  array,
int  size 
)

This function generates pseudorandom 32-bit integers in the specified array[] by one call. The number of pseudorandom integers is specified by the argument size, which must be at least 624 and a multiple of four. The generation by this function is much faster than the following gen_rand function.

For initialization, init_gen_rand or init_by_array must be called before the first call of this function. This function can not be used after calling gen_rand function, without initialization.

Parameters:
array an array where pseudorandom 32-bit integers are filled by this function. The pointer to the array must be "aligned" (namely, must be a multiple of 16) in the SIMD version, since it refers to the address of a 128-bit integer. In the standard C version, the pointer is arbitrary.
size the number of 32-bit pseudorandom integers to be generated. size must be a multiple of 4, and greater than or equal to (MEXP / 128 + 1) * 4.
Note:
memalign or posix_memalign is available to get aligned memory. Mac OSX doesn't have these functions, but malloc of OSX returns the pointer to the aligned memory block.

Definition at line 481 of file SFMT.cpp.

References gen_rand_array(), idx, initialized, and N32.

void fill_array64 ( uint64_t *  array,
int  size 
)

This function generates pseudorandom 64-bit integers in the specified array[] by one call. The number of pseudorandom integers is specified by the argument size, which must be at least 312 and a multiple of two. The generation by this function is much faster than the following gen_rand function.

For initialization, init_gen_rand or init_by_array must be called before the first call of this function. This function can not be used after calling gen_rand function, without initialization.

Parameters:
array an array where pseudorandom 64-bit integers are filled by this function. The pointer to the array must be "aligned" (namely, must be a multiple of 16) in the SIMD version, since it refers to the address of a 128-bit integer. In the standard C version, the pointer is arbitrary.
size the number of 64-bit pseudorandom integers to be generated. size must be a multiple of 2, and greater than or equal to (MEXP / 128 + 1) * 2
Note:
memalign or posix_memalign is available to get aligned memory. Mac OSX doesn't have these functions, but malloc of OSX returns the pointer to the aligned memory block.

Definition at line 517 of file SFMT.cpp.

References gen_rand_array(), idx, initialized, N32, N64, and cimg_library::cimg::swap().

static uint32_t func1 ( uint32_t  x  )  [inline, static]

This function represents a function used in the initialization by init_by_array

Parameters:
x 32-bit integer
Returns:
32-bit integer

Definition at line 330 of file SFMT.cpp.

Referenced by init_by_array().

static uint32_t func2 ( uint32_t  x  )  [inline, static]

This function represents a function used in the initialization by init_by_array

Parameters:
x 32-bit integer
Returns:
32-bit integer

Definition at line 340 of file SFMT.cpp.

Referenced by init_by_array().

uint32_t gen_rand32 ( void   ) 

This function generates and returns 32-bit pseudorandom number. init_gen_rand or init_by_array must be called before this function.

Returns:
32-bit pseudorandom number

Definition at line 410 of file SFMT.cpp.

References gen_rand_all(), idx, initialized, N32, and psfmt32.

Referenced by genrand_real1(), genrand_real2(), genrand_real3(), and genrand_res53_mix().

uint64_t gen_rand64 ( void   ) 

This function generates and returns 64-bit pseudorandom number. init_gen_rand or init_by_array must be called before this function. The function gen_rand64 should not be called after gen_rand32, unless an initialization is again executed.

Returns:
64-bit pseudorandom number

Definition at line 429 of file SFMT.cpp.

References gen_rand_all(), idx, initialized, N32, psfmt32, and psfmt64.

Referenced by genrand_res53().

static void gen_rand_all ( void   )  [inline, static]

This function fills the internal state array with pseudorandom integers.

Definition at line 251 of file SFMT.cpp.

References do_recursion(), N, and POS1.

Referenced by gen_rand32(), and gen_rand64().

static void gen_rand_array ( w128_t array,
int  size 
) [inline, static]

This function fills the user-specified array with pseudorandom integers.

Parameters:
array an 128-bit array to be filled by pseudorandom numbers.
size number of 128-bit pseudorandom numbers to be generated.

Definition at line 276 of file SFMT.cpp.

References do_recursion(), N, and POS1.

Referenced by fill_array32(), and fill_array64().

const char* get_idstring ( void   ) 

This function returns the identification string. The string shows the word size, the Mersenne exponent, and all parameters of this generator.

Definition at line 382 of file SFMT.cpp.

References IDSTR.

int get_min_array_size32 ( void   ) 

This function returns the minimum size of array used for fill_array32() function.

Returns:
minimum size of array used for fill_array32() function.

Definition at line 391 of file SFMT.cpp.

References N32.

int get_min_array_size64 ( void   ) 

This function returns the minimum size of array used for fill_array64() function.

Returns:
minimum size of array used for fill_array64() function.

Definition at line 400 of file SFMT.cpp.

References N64.

static int idxof ( int  i  )  [inline, static]

This function simulate a 64-bit index of LITTLE ENDIAN in BIG ENDIAN machine.

Definition at line 117 of file SFMT.cpp.

Referenced by init_by_array(), init_gen_rand(), and period_certification().

void init_by_array ( uint32_t *  init_key,
int  key_length 
)

This function initializes the internal state array, with an array of 32-bit integers used as the seeds

Parameters:
init_key the array of 32-bit integers, used as a seed.
key_length the length of init_key.

Definition at line 557 of file SFMT.cpp.

References func1(), func2(), idx, idxof(), initialized, N, N32, period_certification(), and psfmt32.

void init_gen_rand ( uint32_t  seed  ) 

This function initializes the internal state array with a 32-bit integer seed.

Parameters:
seed a 32-bit integer used as the seed.

Definition at line 537 of file SFMT.cpp.

References idx, idxof(), initialized, N32, period_certification(), and psfmt32.

static void lshift128 ( w128_t out,
w128_t const *  in,
int  shift 
) [inline, static]

This function simulates SIMD 128-bit left shift by the standard C. The 128-bit integer given in in is shifted by (shift * 8) bits. This function simulates the LITTLE ENDIAN SIMD.

Parameters:
out the output of this function
in the 128-bit data to be shifted
shift the shift value

Definition at line 184 of file SFMT.cpp.

References W128_T::u.

Referenced by do_recursion().

static void period_certification ( void   )  [static]

This function certificate the period of 2^{MEXP}

Definition at line 347 of file SFMT.cpp.

References idxof(), parity, and psfmt32.

Referenced by init_by_array(), and init_gen_rand().

static void rshift128 ( w128_t out,
w128_t const *  in,
int  shift 
) [inline, static]

This function simulates SIMD 128-bit right shift by the standard C. The 128-bit integer given in in is shifted by (shift * 8) bits. This function simulates the LITTLE ENDIAN SIMD.

Parameters:
out the output of this function
in the 128-bit data to be shifted
shift the shift value

Definition at line 145 of file SFMT.cpp.

References W128_T::u.

Referenced by do_recursion().


Variable Documentation

int idx [static]

index counter to the 32-bit internal state array

Definition at line 80 of file SFMT.cpp.

Referenced by fill_array32(), fill_array64(), gen_rand32(), gen_rand64(), init_by_array(), and init_gen_rand().

int initialized = 0 [static]

a flag: it is 0 if and only if the internal state is not yet initialized.

Definition at line 83 of file SFMT.cpp.

Referenced by fill_array32(), fill_array64(), gen_rand32(), gen_rand64(), init_by_array(), and init_gen_rand().

uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4} [static]

a parity check vector which certificate the period of 2^{MEXP}

Definition at line 85 of file SFMT.cpp.

Referenced by period_certification().

uint32_t* psfmt32 = &sfmt[0].u[0] [static]

the 32bit integer pointer to the 128-bit internal state array

Definition at line 74 of file SFMT.cpp.

Referenced by gen_rand32(), gen_rand64(), init_by_array(), init_gen_rand(), and period_certification().

uint64_t* psfmt64 = (uint64_t *)&sfmt[0].u[0] [static]

the 64bit integer pointer to the 128-bit internal state array

Definition at line 77 of file SFMT.cpp.

Referenced by gen_rand64().

w128_t sfmt[N] [static]

the 128-bit internal state array

Definition at line 72 of file SFMT.cpp.

Referenced by gen_rand_all(), and gen_rand_array().


Generated on Fri Jul 24 11:51:59 2009 for lux by  doxygen 1.5.9