forked from taisei-project/taisei
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandom.h
59 lines (45 loc) · 1.75 KB
/
random.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (c) 2011-2018, Lukas Weber <[email protected]>.
* Copyright (c) 2012-2018, Andrei Alexeyev <[email protected]>.
*/
#pragma once
#include "taisei.h"
#include <stdint.h>
#include <stdbool.h>
#define CMWC_CYCLE 4096 // as Marsaglia recommends
#define CMWC_C_MAX 809430660 // as Marsaglia recommends
struct RandomState {
uint32_t Q[CMWC_CYCLE];
uint32_t c; // must be limited with CMWC_C_MAX
uint32_t i;
bool locked;
};
typedef struct RandomState RandomState;
int tsrand_test(void);
void tsrand_init(RandomState *rnd, uint32_t seed);
void tsrand_switch(RandomState *rnd);
void tsrand_seed_p(RandomState *rnd, uint32_t seed);
uint32_t tsrand_p(RandomState *rnd);
void tsrand_seed(uint32_t seed);
uint32_t tsrand(void);
void tsrand_lock(RandomState *rnd);
void tsrand_unlock(RandomState *rnd);
float frand(void);
float nfrand(void);
void __tsrand_fill_p(RandomState *rnd, int amount, const char *file, unsigned int line);
void __tsrand_fill(int amount, const char *file, unsigned int line);
uint32_t __tsrand_a(int idx, const char *file, unsigned int line);
float __afrand(int idx, const char *file, unsigned int line);
float __anfrand(int idx, const char *file, unsigned int line);
#define tsrand_fill_p(rnd,amount) __tsrand_fill_p(rnd, amount, __FILE__, __LINE__)
#define tsrand_fill(amount) __tsrand_fill(amount, __FILE__, __LINE__)
#define tsrand_a(idx) __tsrand_a(idx, __FILE__, __LINE__)
#define afrand(idx) __afrand(idx, __FILE__, __LINE__)
#define anfrand(idx) __anfrand(idx, __FILE__, __LINE__)
#define TSRAND_MAX UINT32_MAX
#define TSRAND_ARRAY_LIMIT 64
#define srand USE_tsrand_seed_INSTEAD_OF_srand
#define rand USE_tsrand_INSTEAD_OF_rand