PatchworkOS
Loading...
Searching...
No Matches
random.c
Go to the documentation of this file.
1
#include "
random.h
"
2
3
#include <
stdint.h
>
4
#include <
stdlib.h
>
5
6
static
uint64_t
seed
= 0;
7
8
int
random_gen
(
void
)
9
{
10
uint64_t
oldstate =
seed
;
11
12
seed
= oldstate * 6364136223846793005ULL + 1442695040888963407ULL;
13
14
uint32_t
xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
15
uint32_t
rot = oldstate >> 59u;
16
uint32_t
result = (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
17
18
return
(
int
)(result &
RAND_MAX
);
19
}
20
21
void
random_seed
(
unsigned
newSeed)
22
{
23
seed
= newSeed * 6364136223846793005ULL + 1442695040888963407ULL;
24
}
seed
static uint64_t seed
Definition
random.c:6
random_gen
int random_gen(void)
Definition
random.c:8
random_seed
void random_seed(unsigned newSeed)
Definition
random.c:21
random.h
stdint.h
uint32_t
__UINT32_TYPE__ uint32_t
Definition
stdint.h:15
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
stdlib.h
RAND_MAX
#define RAND_MAX
Definition
stdlib.h:36
src
libstd
common
random.c
Generated by
1.9.8