Phasor
3.3.0
Stack VM based Programming Language
Loading...
Searching...
No Matches
random.cpp
Go to the documentation of this file.
1
#include "
random.hpp
"
2
3
// my tiny xorshift+ implementation
4
// (C) Daniel McGuire -- MIT License
5
6
static
uint64_t
s
[2];
7
8
void
PHASORstd_rand_seed
(uint64_t s0, uint64_t s1)
9
{
10
s
[0] = s0;
11
s
[1] = s1;
12
}
13
14
uint64_t
PHASORstd_rand_next
()
15
{
16
uint64_t s1 =
s
[0];
17
uint64_t s0 =
s
[1];
18
19
s
[0] = s0;
20
s1 ^= s1 << 23;
21
s
[1] = s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5);
22
23
return
s
[1] + s0;
24
}
25
26
double
PHASORstd_rand_next_double
()
27
{
28
return
(
PHASORstd_rand_next
() >> 11) * (1.0 / (UINT64_C(1) << 53));
29
}
30
31
int64_t
PHASORstd_rand_next_range
(int64_t min, int64_t max)
32
{
33
return
min + (int64_t)(
PHASORstd_rand_next
() % (uint64_t)(max - min + 1));
34
}
PHASORstd_rand_seed
void PHASORstd_rand_seed(uint64_t s0, uint64_t s1)
Definition
random.cpp:8
PHASORstd_rand_next_double
double PHASORstd_rand_next_double()
Definition
random.cpp:26
PHASORstd_rand_next_range
int64_t PHASORstd_rand_next_range(int64_t min, int64_t max)
Definition
random.cpp:31
s
static uint64_t s[2]
Definition
random.cpp:6
PHASORstd_rand_next
uint64_t PHASORstd_rand_next()
Definition
random.cpp:14
random.hpp
src
Runtime
Stdlib
core
random.cpp
Generated by
1.16.1