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
#include <
phsint.hpp
>
3
4
// my tiny xorshift+ implementation
5
// (C) Daniel McGuire -- MIT License
6
7
static
Phasor::u64
s
[2];
8
9
void
PHASORstd_rand_seed
(
Phasor::u64
s0,
Phasor::u64
s1)
10
{
11
s
[0] = s0;
12
s
[1] = s1;
13
}
14
15
Phasor::u64
PHASORstd_rand_next
()
16
{
17
Phasor::u64
s1 =
s
[0];
18
Phasor::u64
s0 =
s
[1];
19
20
s
[0] = s0;
21
s1 ^= s1 << 23;
22
s
[1] = s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5);
23
24
return
s
[1] + s0;
25
}
26
27
Phasor::f64
PHASORstd_rand_next_double
()
28
{
29
return
(
PHASORstd_rand_next
() >> 11) * (1.0 / (UINT64_C(1) << 53));
30
}
31
32
Phasor::i64
PHASORstd_rand_next_range
(
Phasor::i64
min,
Phasor::i64
max)
33
{
34
return
min + (
Phasor::i64
)(
PHASORstd_rand_next
() % (
Phasor::u64
)(max - min + 1));
35
}
PHASORstd_rand_next
Phasor::u64 PHASORstd_rand_next()
Definition
random.cpp:15
PHASORstd_rand_next_double
Phasor::f64 PHASORstd_rand_next_double()
Definition
random.cpp:27
s
static Phasor::u64 s[2]
Definition
random.cpp:7
PHASORstd_rand_seed
void PHASORstd_rand_seed(Phasor::u64 s0, Phasor::u64 s1)
Definition
random.cpp:9
PHASORstd_rand_next_range
Phasor::i64 PHASORstd_rand_next_range(Phasor::i64 min, Phasor::i64 max)
Definition
random.cpp:32
Phasor::i64
int64_t i64
Definition
phsint.hpp:16
Phasor::f64
double f64
Definition
phsint.hpp:7
Phasor::u64
uint64_t u64
Definition
phsint.hpp:12
phsint.hpp
random.hpp
src
Runtime
Stdlib
core
random.cpp
Generated by
1.16.1