alpaka
Abstraction Library for Parallel Kernel Acceleration
tinymt32.h File Reference

Tiny Mersenne Twister only 127 bit internal state. More...

#include "alpaka/core/BoostPredef.hpp"
#include <cstdint>
#include <cinttypes>

Go to the source code of this file.

Classes

struct  TINYMT32_T
 

Macros

#define MIN_LOOP   8
 
#define PRE_LOOP   8
 
#define TINYMT32_MASK   UINT32_C(0x7fffffff)
 
#define TINYMT32_MEXP   127
 
#define TINYMT32_MUL   (1.0f / 16777216.0f)
 
#define TINYMT32_SH0   1
 
#define TINYMT32_SH1   10
 
#define TINYMT32_SH8   8
 
#define UINT32_C(value)   uint_least32_t(value)
 
#define UINT32_MAX   ((uint32_t)-1u)
 

Typedefs

typedef struct TINYMT32_T tinymt32_t
 

Functions

static uint32_t ini_func1 (uint32_t x)
 
static uint32_t ini_func2 (uint32_t x)
 
static void period_certification (tinymt32_t *random)
 
static double tinymt32_generate_32double (tinymt32_t *random)
 
static float tinymt32_generate_float (tinymt32_t *random)
 
static float tinymt32_generate_float01 (tinymt32_t *random)
 
static float tinymt32_generate_float12 (tinymt32_t *random)
 
static float tinymt32_generate_floatOC (tinymt32_t *random)
 
static float tinymt32_generate_floatOO (tinymt32_t *random)
 
static uint32_t tinymt32_generate_uint32 (tinymt32_t *random)
 
static int tinymt32_get_mexp (tinymt32_t *random)
 
void tinymt32_init (tinymt32_t *random, uint32_t seed)
 
void tinymt32_init_by_array (tinymt32_t *random, uint32_t init_key[], int key_length)
 
static void tinymt32_next_state (tinymt32_t *random)
 
static uint32_t tinymt32_temper (tinymt32_t *random)
 
static float tinymt32_temper_conv (tinymt32_t *random)
 
static float tinymt32_temper_conv_open (tinymt32_t *random)
 

Detailed Description

Tiny Mersenne Twister only 127 bit internal state.

Author
Mutsuo Saito (Hiroshima University)
Makoto Matsumoto (University of Tokyo)

Copyright (C) 2011 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

Definition in file tinymt32.h.

Macro Definition Documentation

◆ MIN_LOOP

#define MIN_LOOP   8

Definition at line 286 of file tinymt32.h.

◆ PRE_LOOP

#define PRE_LOOP   8

Definition at line 287 of file tinymt32.h.

◆ TINYMT32_MASK

#define TINYMT32_MASK   UINT32_C(0x7fffffff)

Definition at line 55 of file tinymt32.h.

◆ TINYMT32_MEXP

#define TINYMT32_MEXP   127

Definition at line 51 of file tinymt32.h.

◆ TINYMT32_MUL

#define TINYMT32_MUL   (1.0f / 16777216.0f)

Definition at line 56 of file tinymt32.h.

◆ TINYMT32_SH0

#define TINYMT32_SH0   1

Definition at line 52 of file tinymt32.h.

◆ TINYMT32_SH1

#define TINYMT32_SH1   10

Definition at line 53 of file tinymt32.h.

◆ TINYMT32_SH8

#define TINYMT32_SH8   8

Definition at line 54 of file tinymt32.h.

◆ UINT32_C

#define UINT32_C (   value)    uint_least32_t(value)

Definition at line 33 of file tinymt32.h.

◆ UINT32_MAX

#define UINT32_MAX   ((uint32_t)-1u)

Definition at line 30 of file tinymt32.h.

Typedef Documentation

◆ tinymt32_t

typedef struct TINYMT32_T tinymt32_t

Definition at line 1 of file tinymt32.h.

Function Documentation

◆ ini_func1()

static uint32_t ini_func1 ( uint32_t  x)
static

This function represents a function used in the initialization by init_by_array

Parameters
x32-bit integer
Returns
32-bit integer

Definition at line 295 of file tinymt32.h.

◆ ini_func2()

static uint32_t ini_func2 ( uint32_t  x)
static

This function represents a function used in the initialization by init_by_array

Parameters
x32-bit integer
Returns
32-bit integer

Definition at line 305 of file tinymt32.h.

◆ period_certification()

static void period_certification ( tinymt32_t random)
static

This function certificate the period of 2^127-1.

Parameters
randomtinymt state vector.

Definition at line 313 of file tinymt32.h.

◆ tinymt32_generate_32double()

static double tinymt32_generate_32double ( tinymt32_t random)
inlinestatic

This function outputs double precision floating point number from internal state. The returned value has 32-bit precision. In other words, this function makes one double precision floating point number from one 32-bit unsigned integer.

Parameters
randomtinymt internal status
Returns
floating point number r (0.0 <= r < 1.0)

Definition at line 277 of file tinymt32.h.

◆ tinymt32_generate_float()

static float tinymt32_generate_float ( tinymt32_t random)
inlinestatic

This function outputs floating point number from internal state. This function is implemented using multiplying by (1 / 2^24). floating point multiplication is faster than using union trick in my Intel CPU.

Parameters
randomtinymt internal status
Returns
floating point number r (0.0 <= r < 1.0)

Definition at line 220 of file tinymt32.h.

◆ tinymt32_generate_float01()

static float tinymt32_generate_float01 ( tinymt32_t random)
inlinestatic

This function outputs floating point number from internal state. This function is implemented using union trick.

Parameters
randomtinymt internal status
Returns
floating point number r (0.0 <= r < 1.0)

Definition at line 242 of file tinymt32.h.

◆ tinymt32_generate_float12()

static float tinymt32_generate_float12 ( tinymt32_t random)
inlinestatic

This function outputs floating point number from internal state. This function is implemented using union trick.

Parameters
randomtinymt internal status
Returns
floating point number r (1.0 <= r < 2.0)

Definition at line 231 of file tinymt32.h.

◆ tinymt32_generate_floatOC()

static float tinymt32_generate_floatOC ( tinymt32_t random)
inlinestatic

This function outputs floating point number from internal state. This function may return 1.0 and never returns 0.0.

Parameters
randomtinymt internal status
Returns
floating point number r (0.0 < r <= 1.0)

Definition at line 253 of file tinymt32.h.

◆ tinymt32_generate_floatOO()

static float tinymt32_generate_floatOO ( tinymt32_t random)
inlinestatic

This function outputs floating point number from internal state. This function returns neither 0.0 nor 1.0.

Parameters
randomtinymt internal status
Returns
floating point number r (0.0 < r < 1.0)

Definition at line 264 of file tinymt32.h.

◆ tinymt32_generate_uint32()

static uint32_t tinymt32_generate_uint32 ( tinymt32_t random)
inlinestatic

This function outputs 32-bit unsigned integer from internal state.

Parameters
randomtinymt internal status
Returns
32-bit unsigned integer r (0 <= r < 2^32)

Definition at line 207 of file tinymt32.h.

◆ tinymt32_get_mexp()

static int tinymt32_get_mexp ( tinymt32_t random)
inlinestatic

Definition at line 89 of file tinymt32.h.

◆ tinymt32_init()

void tinymt32_init ( tinymt32_t random,
uint32_t  seed 
)
inline

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

Parameters
randomtinymt state vector.
seeda 32-bit unsigned integer used as a seed.

Definition at line 331 of file tinymt32.h.

◆ tinymt32_init_by_array()

void tinymt32_init_by_array ( tinymt32_t random,
uint32_t  init_key[],
int  key_length 
)
inline

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

Parameters
randomtinymt state vector.
init_keythe array of 32-bit integers, used as a seed.
key_lengththe length of init_key.

Definition at line 354 of file tinymt32.h.

◆ tinymt32_next_state()

static void tinymt32_next_state ( tinymt32_t random)
inlinestatic

This function changes internal state of tinymt32. Users should not call this function directly.

Parameters
randomtinymt internal status

Definition at line 99 of file tinymt32.h.

◆ tinymt32_temper()

static uint32_t tinymt32_temper ( tinymt32_t random)
inlinestatic

This function outputs 32-bit unsigned integer from internal state. Users should not call this function directly.

Parameters
randomtinymt internal status
Returns
32-bit unsigned pseudorandom number

Definition at line 125 of file tinymt32.h.

◆ tinymt32_temper_conv()

static float tinymt32_temper_conv ( tinymt32_t random)
inlinestatic

This function outputs floating point number from internal state. Users should not call this function directly.

Parameters
randomtinymt internal status
Returns
floating point number r (1.0 <= r < 2.0)

Definition at line 148 of file tinymt32.h.

◆ tinymt32_temper_conv_open()

static float tinymt32_temper_conv_open ( tinymt32_t random)
inlinestatic

This function outputs floating point number from internal state. Users should not call this function directly.

Parameters
randomtinymt internal status
Returns
floating point number r (1.0 < r < 2.0)

Definition at line 178 of file tinymt32.h.