31#ifndef ETL_RANDOM_INCLUDED
32#define ETL_RANDOM_INCLUDED
41#if defined(ETL_POLYMORPHIC_RANDOM)
51 virtual void initialise(uint32_t seed) = 0;
52 virtual uint32_t operator()() = 0;
53 virtual uint32_t range(uint32_t low, uint32_t high) = 0;
87 uintptr_t n =
reinterpret_cast<uintptr_t
>(
this);
88 uint32_t seed =
static_cast<uint32_t
>(n);
111 state[3] = seed + 11;
119 uint32_t n = state[3];
126 n ^= state[0] >> 19U;
135 uint32_t
range(uint32_t low, uint32_t high)
137 uint32_t r = high - low + 1UL;
167 uintptr_t n =
reinterpret_cast<uintptr_t
>(
this);
168 uint32_t seed =
static_cast<uint32_t
>(n);
187 seed = (seed == 0) ? 1 : seed;
188 value = (seed > m) ? m : seed;
196 value = (a * value) % m;
204 uint32_t
range(uint32_t low, uint32_t high)
206 uint32_t r = high - low + 1UL;
216 static ETL_CONSTANT uint32_t a = 40014U;
217 static ETL_CONSTANT uint32_t m = 2147483563UL;
239 uintptr_t n =
reinterpret_cast<uintptr_t
>(
this);
240 uint32_t seed =
static_cast<uint32_t
>(n);
259 seed = (seed == 0) ? 1 : seed;
260 value1 = (seed > m1) ? m1 : seed;
261 value2 = (seed > m1) ? m1 : seed;
269 static ETL_CONSTANT uint32_t m = ((m1 > m2) ? m1 : m2);
271 value1 = (a1 * value1) % m1;
272 value2 = (a2 * value2) % m2;
274 return (value1 + value2) % m;
280 uint32_t
range(uint32_t low, uint32_t high)
282 uint32_t r = high - low + 1UL;
292 static ETL_CONSTANT uint32_t a1 = 40014U;
293 static ETL_CONSTANT uint32_t m1 = 2147483563UL;
295 static ETL_CONSTANT uint32_t a2 = 40692U;
296 static ETL_CONSTANT uint32_t m2 = 2147483399UL;
320 uintptr_t n =
reinterpret_cast<uintptr_t
>(
this);
321 uint32_t seed =
static_cast<uint32_t
>(n);
348 static ETL_CONSTANT uint32_t polynomial = 0x80200003UL;
352 if ((value & 1UL) == 1UL)
363 uint32_t
range(uint32_t low, uint32_t high)
365 uint32_t r = high - low + 1UL;
394 uintptr_t n =
reinterpret_cast<uintptr_t
>(
this);
395 uint32_t seed =
static_cast<uint32_t
>(n);
423 value1 = 36969UL * (value1 & 0xFFFFUL) + (value1 >> 16U);
424 value2 = 18000UL * (value2 & 0xFFFFUL) + (value2 >> 16U);
426 return (value1 << 16U) + value2;
432 uint32_t
range(uint32_t low, uint32_t high)
434 uint32_t r = high - low + 1UL;
448#if ETL_USING_64BIT_TYPES
463 uintptr_t n =
reinterpret_cast<uintptr_t
>(
this);
464 value =
static_cast<uint64_t
>(n);
483 value = uint64_t(seed) | (uint64_t(seed) << 32U);
492 unsigned count = (unsigned)(value >> 59U);
494 value = (x * multiplier) + increment;
502 uint32_t
range(uint32_t low, uint32_t high)
504 uint32_t r = high - low + 1UL;
514 static ETL_CONSTANT uint64_t multiplier = 6364136223846793005ULL;
515 static ETL_CONSTANT uint64_t increment = 1ULL;
521#if ETL_USING_8BIT_TYPES
528 template <
typename THash>
529 class random_hash :
public random
537 uintptr_t n =
reinterpret_cast<uintptr_t
>(
this);
538 value =
static_cast<uint32_t
>(n);
545 random_hash(uint32_t seed)
554 void initialise(uint32_t seed)
562 uint32_t operator()()
572 uint32_t range(uint32_t low, uint32_t high)
574 uint32_t r = high - low + 1UL;
575 uint32_t n = operator()();
random_clcg()
Definition random.h:235
void initialise(uint32_t seed)
Definition random.h:257
random_clcg(uint32_t seed)
Definition random.h:248
uint32_t range(uint32_t low, uint32_t high)
Get the next random_clcg number in a specified inclusive range.
Definition random.h:280
uint32_t operator()()
Get the next random_clcg number.
Definition random.h:267
random_lcg(uint32_t seed)
Definition random.h:176
random_lcg()
Definition random.h:163
void initialise(uint32_t seed)
Definition random.h:185
uint32_t operator()()
Get the next random_clcg number.
Definition random.h:194
uint32_t range(uint32_t low, uint32_t high)
Get the next random_clcg number in a specified inclusive range.
Definition random.h:204
random_lsfr(uint32_t seed)
Definition random.h:329
random_lsfr()
Definition random.h:316
void initialise(uint32_t seed)
Definition random.h:338
uint32_t range(uint32_t low, uint32_t high)
Get the next random_lsfr number in a specified inclusive range.
Definition random.h:363
uint32_t operator()()
Get the next random_lsfr number.
Definition random.h:346
random_mwc()
Definition random.h:390
uint32_t range(uint32_t low, uint32_t high)
Get the next random_lsfr number in a specified inclusive range.
Definition random.h:432
uint32_t operator()()
Get the next random_lsfr number.
Definition random.h:421
random_mwc(uint32_t seed)
Definition random.h:403
void initialise(uint32_t seed)
Definition random.h:412
random_pcg(uint32_t seed)
Definition random.h:472
void initialise(uint32_t seed)
Definition random.h:481
uint32_t operator()()
Get the next random_lsfr number.
Definition random.h:489
uint32_t range(uint32_t low, uint32_t high)
Get the next random_lsfr number in a specified inclusive range.
Definition random.h:502
uint32_t operator()()
Get the next random_xorshift number.
Definition random.h:117
random_xorshift(uint32_t seed)
Definition random.h:96
random_xorshift()
Definition random.h:83
uint32_t range(uint32_t low, uint32_t high)
Get the next random_xorshift number in a specified inclusive range.
Definition random.h:135
void initialise(uint32_t seed)
Definition random.h:105
ETL_CONSTEXPR14 T rotate_right(T value)
Definition binary.h:162
bitset_ext
Definition absolute.h:40