SFMT  1.4
Defines | Functions | Variables
SFMT.c File Reference

SIMD oriented Fast Mersenne Twister(SFMT) More...

#include <string.h>
#include <assert.h>
#include "SFMT.h"
#include "SFMT-params.h"
#include "SFMT-common.h"

Defines

#define UNUSED_VARIABLE(x)   (void)(x)

Functions

static int idxof (int i)
 This function simulate a 64-bit index of LITTLE ENDIAN in BIG ENDIAN machine.
static void gen_rand_array (sfmt_t *sfmt, w128_t *array, int size)
 This function fills the user-specified array with pseudorandom integers.
static uint32_t func1 (uint32_t x)
 This function represents a function used in the initialization by init_by_array.
static uint32_t func2 (uint32_t x)
 This function represents a function used in the initialization by init_by_array.
static void period_certification (sfmt_t *sfmt)
 This function certificate the period of 2^{MEXP}.
const char * sfmt_get_idstring (sfmt_t *sfmt)
 This function returns the identification string.
int sfmt_get_min_array_size32 (sfmt_t *sfmt)
 This function returns the minimum size of array used for fill_array32() function.
int sfmt_get_min_array_size64 (sfmt_t *sfmt)
 This function returns the minimum size of array used for fill_array64() function.
void sfmt_gen_rand_all (sfmt_t *sfmt)
 This function fills the internal state array with pseudorandom integers.
void sfmt_fill_array32 (sfmt_t *sfmt, uint32_t *array, int size)
 This function generates pseudorandom 32-bit integers in the specified array[] by one call.
void sfmt_fill_array64 (sfmt_t *sfmt, uint64_t *array, int size)
 This function generates pseudorandom 64-bit integers in the specified array[] by one call.
void sfmt_init_gen_rand (sfmt_t *sfmt, uint32_t seed)
 This function initializes the internal state array with a 32-bit integer seed.
void sfmt_init_by_array (sfmt_t *sfmt, 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.

Variables

static const w128_t sse2_param_mask
 parameters used by sse2.

Detailed Description

SIMD oriented Fast Mersenne Twister(SFMT)

Author:
Mutsuo Saito (Hiroshima University)
Makoto Matsumoto (Hiroshima University)

Copyright (C) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima University. Copyright (C) 2012 Mutsuo Saito, Makoto Matsumoto, Hiroshima University and The University of Tokyo. All rights reserved.

The 3-clause BSD License is applied to this software, see LICENSE.txt


Define Documentation

#define UNUSED_VARIABLE (   x)    (void)(x)

Function Documentation

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

This function represents a function used in the initialization by init_by_array.

Parameters:
x32-bit integer
Returns:
32-bit integer

Referenced by sfmt_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:
x32-bit integer
Returns:
32-bit integer

Referenced by sfmt_init_by_array().

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

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

Parameters:
sfmtSFMT internal state
arrayan 128-bit array to be filled by pseudorandom numbers.
sizenumber of 128-bit pseudorandom numbers to be generated.

References SFMT_T::state.

Referenced by sfmt_fill_array32(), and sfmt_fill_array64().

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

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

Referenced by period_certification(), sfmt_init_by_array(), and sfmt_init_gen_rand().

static void period_certification ( sfmt_t sfmt) [static]

This function certificate the period of 2^{MEXP}.

Parameters:
sfmtSFMT internal state

References idxof(), SFMT_T::state, and W128_T::u.

Referenced by sfmt_init_by_array(), and sfmt_init_gen_rand().

void sfmt_fill_array32 ( sfmt_t sfmt,
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:
sfmtSFMT internal state
arrayan 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.
sizethe 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.

References gen_rand_array(), and SFMT_T::idx.

void sfmt_fill_array64 ( sfmt_t sfmt,
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.

Parameters:
sfmtSFMT internal state 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.
arrayan 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.
sizethe 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.

References gen_rand_array(), and SFMT_T::idx.

void sfmt_gen_rand_all ( sfmt_t sfmt)

This function fills the internal state array with pseudorandom integers.

Parameters:
sfmtSFMT internal state

References SFMT_T::state.

Referenced by sfmt_genrand_uint32(), and sfmt_genrand_uint64().

const char* sfmt_get_idstring ( sfmt_t sfmt)

This function returns the identification string.

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

Parameters:
sfmtSFMT internal state

References UNUSED_VARIABLE.

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

Parameters:
sfmtSFMT internal state
Returns:
minimum size of array used for fill_array32() function.

References UNUSED_VARIABLE.

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

Parameters:
sfmtSFMT internal state
Returns:
minimum size of array used for fill_array64() function.

References UNUSED_VARIABLE.

void sfmt_init_by_array ( sfmt_t sfmt,
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:
sfmtSFMT internal state
init_keythe array of 32-bit integers, used as a seed.
key_lengththe length of init_key.

References func1(), func2(), SFMT_T::idx, idxof(), period_certification(), SFMT_T::state, and W128_T::u.

void sfmt_init_gen_rand ( sfmt_t sfmt,
uint32_t  seed 
)

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

Parameters:
sfmtSFMT internal state
seeda 32-bit integer used as the seed.

References SFMT_T::idx, idxof(), period_certification(), SFMT_T::state, and W128_T::u.


Variable Documentation

const w128_t sse2_param_mask [static]
Initial value:
 {{SFMT_MSK1, SFMT_MSK2,
                                        SFMT_MSK3, SFMT_MSK4}}

parameters used by sse2.