i32
This commit is contained in:
@@ -12,8 +12,8 @@ extern "C" {
|
||||
/*
|
||||
You can choose any algorithm that has required functions:
|
||||
|
||||
some_alg32_statePtr some_alg32_init(uint32 seed);
|
||||
uint32 some_alg32_next(some_alg32_statePtr);
|
||||
some_alg32_statePtr some_alg32_init(u32 seed);
|
||||
u32 some_alg32_next(some_alg32_statePtr);
|
||||
void some_alg32_free(some_alg32_statePtr);
|
||||
|
||||
#define KRAND_ALG32_init some_alg32_init
|
||||
@@ -51,19 +51,19 @@ typedef void* krand_statePtr;
|
||||
#define __krand_next_definition(VALUE_SIZE) { return from+KRAND_ALG##VALUE_SIZE##_next(state)%(to-from); }
|
||||
|
||||
// ready-to-use functions
|
||||
static inline int8 krand_next8 (krand_statePtr state, int8 from, int8 to) __krand_next_definition(32)
|
||||
static inline int16 krand_next16(krand_statePtr state, int16 from, int16 to) __krand_next_definition(32)
|
||||
static inline int32 krand_next32(krand_statePtr state, int32 from, int32 to) __krand_next_definition(32)
|
||||
static inline int64 krand_next64(krand_statePtr state, int64 from, int64 to) __krand_next_definition(64)
|
||||
static inline i8 krand_next8 (krand_statePtr state, i8 from, i8 to) __krand_next_definition(32)
|
||||
static inline i16 krand_next16(krand_statePtr state, i16 from, i16 to) __krand_next_definition(32)
|
||||
static inline i32 krand_next32(krand_statePtr state, i32 from, i32 to) __krand_next_definition(32)
|
||||
static inline i64 krand_next64(krand_statePtr state, i64 from, i64 to) __krand_next_definition(64)
|
||||
|
||||
// divides random number by 2^64 to return a value between 0 and 1
|
||||
static inline float32 krand_nextFloat32(krand_statePtr state) {return (uint32)KRAND_ALG32_next(state)/0xffffffff; }
|
||||
static inline float64 krand_nextFloat64(krand_statePtr state) {return KRAND_ALG64_next(state)/0xffffffff; }
|
||||
static inline f32 krand_nextFloat32(krand_statePtr state) {return (u32)KRAND_ALG32_next(state)/0xffffffff; }
|
||||
static inline f64 krand_nextFloat64(krand_statePtr state) {return KRAND_ALG64_next(state)/0xffffffff; }
|
||||
|
||||
|
||||
///@param chance (0-1.0) is probability of success
|
||||
static inline bool fate(krand_statePtr state,float chance){
|
||||
int limit=1/chance + 0.01f;
|
||||
i32 limit=1/chance + 0.01f;
|
||||
return KRAND_ALG32_next(state)%limit == 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user