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
|
|
|
* ---
|
2018-01-04 18:14:31 +01:00
|
|
|
* Copyright (c) 2011-2018, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2018, Andrei Alexeyev <akari@alienslab.net>.
|
2012-07-27 19:11:45 +02:00
|
|
|
*/
|
|
|
|
|
2017-09-27 14:14:53 +02:00
|
|
|
#pragma once
|
2017-11-25 20:45:11 +01:00
|
|
|
#include "taisei.h"
|
2012-07-27 19:11:45 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2017-02-27 15:27:48 +01:00
|
|
|
#include <stdbool.h>
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2017-12-04 04:26:27 +01:00
|
|
|
#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;
|
2017-02-11 04:52:08 +01:00
|
|
|
bool locked;
|
2017-12-04 04:26:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct RandomState RandomState;
|
2012-07-27 19:11:45 +02:00
|
|
|
|
|
|
|
int tsrand_test(void);
|
2017-02-05 21:16:50 +01:00
|
|
|
|
|
|
|
void tsrand_init(RandomState *rnd, uint32_t seed);
|
2012-07-27 19:11:45 +02:00
|
|
|
void tsrand_switch(RandomState *rnd);
|
|
|
|
void tsrand_seed_p(RandomState *rnd, uint32_t seed);
|
2017-02-05 21:16:50 +01:00
|
|
|
uint32_t tsrand_p(RandomState *rnd);
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2012-08-10 21:27:46 +02:00
|
|
|
void tsrand_seed(uint32_t seed);
|
2017-02-05 21:16:50 +01:00
|
|
|
uint32_t tsrand(void);
|
|
|
|
|
|
|
|
void tsrand_lock(RandomState *rnd);
|
|
|
|
void tsrand_unlock(RandomState *rnd);
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2017-12-04 04:26:27 +01:00
|
|
|
float frand(void);
|
|
|
|
float nfrand(void);
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2017-02-06 23:37:42 +01:00
|
|
|
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);
|
2017-12-04 04:26:27 +01:00
|
|
|
float __afrand(int idx, const char *file, unsigned int line);
|
|
|
|
float __anfrand(int idx, const char *file, unsigned int line);
|
2017-02-05 21:16:50 +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-08-04 02:49:12 +02:00
|
|
|
|
2017-12-04 04:26:27 +01:00
|
|
|
#define TSRAND_MAX UINT32_MAX
|
2012-07-27 19:11:45 +02:00
|
|
|
|
2017-02-05 21:16:50 +01:00
|
|
|
#define TSRAND_ARRAY_LIMIT 64
|
2012-07-27 19:11:45 +02:00
|
|
|
#define srand USE_tsrand_seed_INSTEAD_OF_srand
|
|
|
|
#define rand USE_tsrand_INSTEAD_OF_rand
|