random: remove old API
This commit is contained in:
parent
b916d62e39
commit
ccc8f018ac
2 changed files with 0 additions and 129 deletions
96
src/random.c
96
src/random.c
|
@ -182,99 +182,3 @@ bool vrng_f64_chance(rng_val_t v, double chance) {
|
|||
bool vrng_f32_chance(rng_val_t v, float chance) {
|
||||
return vrng_f32(v) < chance;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deprecated APIs; to be removed
|
||||
*/
|
||||
|
||||
DIAGNOSTIC(ignored "-Wdeprecated-declarations")
|
||||
|
||||
uint32_t tsrand_p(RandomState *rng) {
|
||||
return vrng_u32(rng_next_p(rng));
|
||||
}
|
||||
|
||||
uint64_t tsrand64_p(RandomState *rng) {
|
||||
return vrng_u64(rng_next_p(rng));
|
||||
}
|
||||
|
||||
uint32_t tsrand(void) {
|
||||
return rng_u32();
|
||||
}
|
||||
|
||||
uint64_t tsrand64(void) {
|
||||
return rng_u64();
|
||||
}
|
||||
|
||||
double frand(void) {
|
||||
return rng_f64();
|
||||
}
|
||||
|
||||
double nfrand(void) {
|
||||
return rng_f64s();
|
||||
}
|
||||
|
||||
static rng_val_t tsrand_array[TSRAND_ARRAY_LIMIT];
|
||||
static int tsrand_array_elems;
|
||||
static uint64_t tsrand_fillflags = 0;
|
||||
|
||||
noreturn static void tsrand_error(const char *file, const char *func, uint line, const char *fmt, ...) {
|
||||
char buf[2048] = { 0 };
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
log_fatal("%s(): %s [%s:%u]", func, buf, file, line);
|
||||
UNREACHABLE;
|
||||
}
|
||||
|
||||
#define TSRANDERR(...) tsrand_error(file, __func__, line, __VA_ARGS__)
|
||||
|
||||
void _tsrand_fill_p(RandomState *rnd, int amount, const char *file, uint line) {
|
||||
if(tsrand_fillflags) {
|
||||
TSRANDERR("Some indices left unused from the previous call");
|
||||
return;
|
||||
}
|
||||
|
||||
tsrand_array_elems = amount;
|
||||
tsrand_fillflags = (UINT64_C(1) << amount) - 1;
|
||||
|
||||
for(int i = 0; i < amount; ++i) {
|
||||
tsrand_array[i] = rng_next_p(rnd);
|
||||
}
|
||||
}
|
||||
|
||||
void _tsrand_fill(int amount, const char *file, uint line) {
|
||||
_tsrand_fill_p(rng_active_state, amount, file, line);
|
||||
}
|
||||
|
||||
static rng_val_t _tsrand_val_a(int idx, const char *file, uint line) {
|
||||
if(idx >= tsrand_array_elems || idx < 0) {
|
||||
TSRANDERR("Index out of range (%i / %i)", idx, tsrand_array_elems);
|
||||
}
|
||||
|
||||
if(tsrand_fillflags & (UINT64_C(1) << idx)) {
|
||||
tsrand_fillflags &= ~(UINT64_C(1) << idx);
|
||||
return tsrand_array[idx];
|
||||
}
|
||||
|
||||
TSRANDERR("Index %i used multiple times", idx);
|
||||
}
|
||||
|
||||
|
||||
uint64_t _tsrand64_a(int idx, const char *file, uint line) {
|
||||
return vrng_u64(_tsrand_val_a(idx, file, line));
|
||||
}
|
||||
|
||||
uint32_t _tsrand_a(int idx, const char *file, uint line) {
|
||||
return vrng_u32(_tsrand_val_a(idx, file, line));
|
||||
}
|
||||
|
||||
double _afrand(int idx, const char *file, uint line) {
|
||||
return vrng_f64(_tsrand_val_a(idx, file, line));
|
||||
}
|
||||
|
||||
double _anfrand(int idx, const char *file, uint line) {
|
||||
return vrng_f64s(_tsrand_val_a(idx, file, line));
|
||||
}
|
||||
|
|
33
src/random.h
33
src/random.h
|
@ -12,8 +12,6 @@
|
|||
#include "util/crap.h"
|
||||
#include "util/miscmath.h"
|
||||
|
||||
#define RNG_DEPRECATED attr_deprecated("Use the new rng_ API")
|
||||
|
||||
typedef struct RandomState {
|
||||
uint64_t state[4];
|
||||
#ifdef DEBUG
|
||||
|
@ -138,34 +136,3 @@ bool vrng_f32_chance(rng_val_t v, float chance) attr_pure;
|
|||
)(v, chance)
|
||||
|
||||
#define rng_chance(chance) vrng_chance(rng_next(), chance)
|
||||
|
||||
/*
|
||||
* Deprecated APIs; to be removed
|
||||
*/
|
||||
|
||||
uint32_t tsrand_p(RandomState *rng) RNG_DEPRECATED;
|
||||
uint64_t tsrand64_p(RandomState *rng) RNG_DEPRECATED;
|
||||
|
||||
uint32_t tsrand(void) RNG_DEPRECATED;
|
||||
uint64_t tsrand64(void) RNG_DEPRECATED;
|
||||
|
||||
double frand(void) RNG_DEPRECATED; // Range: [0.0; 1.0)
|
||||
double nfrand(void) RNG_DEPRECATED; // Range: (-1.0; 1.0)
|
||||
bool rand_bool(void) RNG_DEPRECATED;
|
||||
double rand_sign(void) RNG_DEPRECATED; // 1.0 or -1.0
|
||||
float rand_signf(void) RNG_DEPRECATED; // 1.0f or -1.0f
|
||||
|
||||
void _tsrand_fill_p(RandomState *rnd, int amount, const char *file, uint line) RNG_DEPRECATED;
|
||||
void _tsrand_fill(int amount, const char *file, uint line) RNG_DEPRECATED;
|
||||
uint32_t _tsrand_a(int idx, const char *file, uint line) RNG_DEPRECATED;
|
||||
uint64_t _tsrand64_a(int idx, const char *file, uint line) RNG_DEPRECATED;
|
||||
double _afrand(int idx, const char *file, uint line) RNG_DEPRECATED;
|
||||
double _anfrand(int idx, const char *file, uint line) RNG_DEPRECATED;
|
||||
|
||||
#define tsrand_fill_p(rnd,amount) _tsrand_fill_p(rnd, amount, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define tsrand_fill(amount) _tsrand_fill(amount, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define tsrand_a(idx) _tsrand_a(idx, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define afrand(idx) _afrand(idx, _TAISEI_SRC_FILE, __LINE__)
|
||||
#define anfrand(idx) _anfrand(idx, _TAISEI_SRC_FILE, __LINE__)
|
||||
|
||||
#define TSRAND_ARRAY_LIMIT 16
|
||||
|
|
Loading…
Reference in a new issue