2018-08-21 21:23:22 +02:00
|
|
|
#ifndef RANDOM_H
|
|
|
|
#define RANDOM_H
|
|
|
|
|
2018-08-23 22:30:44 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#define RANDOM_CACHE_SIZE 4096
|
|
|
|
|
2018-08-21 21:23:22 +02:00
|
|
|
struct random_state {
|
2018-08-23 22:30:44 +02:00
|
|
|
size_t index;
|
|
|
|
uint8_t cache[RANDOM_CACHE_SIZE];
|
2018-08-21 21:23:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void random_state_init(struct random_state *state);
|
|
|
|
void get_random_bytes(struct random_state *state, void *buf, size_t size);
|
2018-08-26 00:32:44 +02:00
|
|
|
uint16_t get_random_u16(struct random_state *state);
|
|
|
|
uint16_t get_random_u16_uniform(struct random_state *state, uint16_t bound);
|
|
|
|
uint64_t get_random_u64(struct random_state *state);
|
|
|
|
uint64_t get_random_u64_uniform(struct random_state *state, uint64_t bound);
|
2018-08-21 21:23:22 +02:00
|
|
|
|
|
|
|
#endif
|