#include #include #include #include #include #include RNG rng_new_impl(const struct rng_algo *from) { RNG algo = malloc(sizeof(struct rng_algo)); memcpy(algo, from, sizeof(struct rng_algo)); if(algo->construct!=NULL) algo->construct(); return algo; } RNG rng_new(RNG (*instantiate)(void)) { return instantiate(); } void rng_free(RNG algo) { if(algo->destruct!=NULL) algo->destruct(); free(algo); } void rng_seed(RNG algo, void* seed) { if(algo->seed!=NULL) algo->seed(seed); } double rng_next_double(RNG algo) { return algo->sample(); } int rng_next_int_bounded(RNG algo, int min, int max) { return (int)floor(algo->sample() * (double)(max-min))+min; } int rng_next_int(RNG algo, int max) { double sample = algo->sample(); return (int)floor(sample * (double)max); } void* rng_next(RNG algo, void* data, int len) { uint8_t *buffer = data; for(register int i=0;isample()<=d; }