2012-07-27 19:11:45 +02:00
|
|
|
/*
|
|
|
|
* This software is licensed under the terms of the MIT-License
|
2017-02-11 04:52:08 +01:00
|
|
|
* See COPYING for further information.
|
2012-07-27 19:11:45 +02:00
|
|
|
* ---
|
2019-01-23 21:10:43 +01:00
|
|
|
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
2019-07-03 20:00:56 +02:00
|
|
|
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
2012-07-27 19:11:45 +02:00
|
|
|
*/
|
|
|
|
|
2019-01-23 21:10:43 +01:00
|
|
|
#ifndef IGUARD_random_h
|
|
|
|
#define IGUARD_random_h
|
|
|
|
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
typedef struct RandomState {
|
|
|
|
uint64_t state[4];
|
2018-01-12 19:26:07 +01:00
|
|
|
bool locked;
|
2019-03-09 17:19:42 +01:00
|
|
|
} RandomState;
|
2017-12-04 04:26:27 +01:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
uint64_t splitmix64(uint64_t *state);
|
|
|
|
uint64_t makeseed(void);
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
void tsrand_init(RandomState *rnd, uint64_t seed);
|
2012-07-27 19:11:45 +02:00
|
|
|
void tsrand_switch(RandomState *rnd);
|
2019-03-09 17:19:42 +01:00
|
|
|
void tsrand_seed_p(RandomState *rnd, uint64_t seed);
|
2017-02-05 21:16:50 +01:00
|
|
|
uint32_t tsrand_p(RandomState *rnd);
|
2019-03-09 17:19:42 +01:00
|
|
|
uint64_t tsrand64_p(RandomState *rnd);
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
void tsrand_seed(uint64_t seed);
|
2017-02-05 21:16:50 +01:00
|
|
|
uint32_t tsrand(void);
|
2019-03-09 17:19:42 +01:00
|
|
|
uint64_t tsrand64(void);
|
2017-02-05 21:16:50 +01:00
|
|
|
|
|
|
|
void tsrand_lock(RandomState *rnd);
|
|
|
|
void tsrand_unlock(RandomState *rnd);
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
double frand(void);
|
|
|
|
double nfrand(void);
|
2017-02-05 21:16:50 +01:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
void _tsrand_fill_p(RandomState *rnd, int amount, const char *file, uint line);
|
|
|
|
void _tsrand_fill(int amount, const char *file, uint line);
|
|
|
|
uint32_t _tsrand_a(int idx, const char *file, uint line);
|
|
|
|
uint64_t _tsrand64_a(int idx, const char *file, uint line);
|
|
|
|
double _afrand(int idx, const char *file, uint line);
|
|
|
|
double _anfrand(int idx, const char *file, uint line);
|
2012-08-04 02:49:12 +02:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
#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__)
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2019-03-09 17:19:42 +01:00
|
|
|
#define TSRAND_ARRAY_LIMIT 16
|
2019-01-23 21:10:43 +01:00
|
|
|
|
|
|
|
#endif // IGUARD_random_h
|