rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
tinymt32.c File Reference

Detailed Description

Tiny Mersenne Twister only 127 bit internal state.

Author
Mutsuo Saito (Hiroshima University)
Makoto Matsumoto (The 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.c.

Functions

static uint32_t ini_func1 (uint32_t x)
 
static uint32_t ini_func2 (uint32_t x)
 
static void period_certification (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)
 

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 26 of file tinymt32.c.

26 {
27 return (x ^ (x >> 27)) * UINT32_C(1664525);
28}

Referenced by tinymt32_init_by_array().

Here is the caller graph for this function:

◆ 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 36 of file tinymt32.c.

36 {
37 return (x ^ (x >> 27)) * UINT32_C(1566083941);
38}

Referenced by tinymt32_init_by_array().

Here is the caller graph for this function:

◆ 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 44 of file tinymt32.c.

44 {
45 if ((random->status[0] & TINYMT32_MASK) == 0 &&
46 random->status[1] == 0 &&
47 random->status[2] == 0 &&
48 random->status[3] == 0) {
49 random->status[0] = 'T';
50 random->status[1] = 'I';
51 random->status[2] = 'N';
52 random->status[3] = 'Y';
53 }
54}
uint32_t status[4]
Definition tinymt32.h:37

Referenced by tinymt32_init(), and tinymt32_init_by_array().

Here is the caller graph for this function:

◆ tinymt32_init()

void tinymt32_init ( tinymt32_t random,
uint32_t  seed 
)

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 62 of file tinymt32.c.

62 {
63 random->status[0] = seed;
64 random->status[1] = random->mat1;
65 random->status[2] = random->mat2;
66 random->status[3] = random->tmat;
67 for (unsigned int i = 1; i < MIN_LOOP; i++) {
68 random->status[i & 3] ^= i + UINT32_C(1812433253)
69 * (random->status[(i - 1) & 3]
70 ^ (random->status[(i - 1) & 3] >> 30));
71 }
73 for (unsigned int i = 0; i < PRE_LOOP; i++) {
74 tinymt32_next_state(random);
75 }
76}
uint32_t tmat
Definition tinymt32.h:40
uint32_t mat2
Definition tinymt32.h:39
uint32_t mat1
Definition tinymt32.h:38
static void period_certification(tinymt32_t *random)
Definition tinymt32.c:44
static void tinymt32_next_state(tinymt32_t *random)
Definition tinymt32.h:70

Referenced by configureRusefiLuaHooks(), and initLaunchControl().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tinymt32_init_by_array()

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

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 85 of file tinymt32.c.

86 {
87 const unsigned int lag = 1;
88 const unsigned int mid = 1;
89 const unsigned int size = 4;
90 unsigned int i, j;
91 unsigned int count;
92 uint32_t r;
93 uint32_t * st = &random->status[0];
94
95 st[0] = 0;
96 st[1] = random->mat1;
97 st[2] = random->mat2;
98 st[3] = random->tmat;
99 if (key_length + 1 > MIN_LOOP) {
100 count = (unsigned int)key_length + 1;
101 } else {
102 count = MIN_LOOP;
103 }
104 r = ini_func1(st[0] ^ st[mid % size]
105 ^ st[(size - 1) % size]);
106 st[mid % size] += r;
107 r += (unsigned int)key_length;
108 st[(mid + lag) % size] += r;
109 st[0] = r;
110 count--;
111 for (i = 1, j = 0; (j < count) && (j < (unsigned int)key_length); j++) {
112 r = ini_func1(st[i % size]
113 ^ st[(i + mid) % size]
114 ^ st[(i + size - 1) % size]);
115 st[(i + mid) % size] += r;
116 r += init_key[j] + i;
117 st[(i + mid + lag) % size] += r;
118 st[i % size] = r;
119 i = (i + 1) % size;
120 }
121 for (; j < count; j++) {
122 r = ini_func1(st[i % size]
123 ^ st[(i + mid) % size]
124 ^ st[(i + size - 1) % size]);
125 st[(i + mid) % size] += r;
126 r += i;
127 st[(i + mid + lag) % size] += r;
128 st[i % size] = r;
129 i = (i + 1) % size;
130 }
131 for (j = 0; j < size; j++) {
132 r = ini_func2(st[i % size]
133 + st[(i + mid) % size]
134 + st[(i + size - 1) % size]);
135 st[(i + mid) % size] ^= r;
136 r -= i;
137 st[(i + mid + lag) % size] ^= r;
138 st[i % size] = r;
139 i = (i + 1) % size;
140 }
141 period_certification(random);
142 for (i = 0; i < PRE_LOOP; i++) {
143 tinymt32_next_state(random);
144 }
145}
static uint32_t ini_func2(uint32_t x)
Definition tinymt32.c:36
static uint32_t ini_func1(uint32_t x)
Definition tinymt32.c:26
composite packet size
uint16_t count
Definition tunerstudio.h:1
Here is the call graph for this function:

Go to the source code of this file.