aboutsummaryrefslogtreecommitdiff
path: root/rng.h
blob: 9ce2abd9861d04b886a5d72acd3e85b88aa5d236 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once

#include <string>
#include <cstdint>

class Rng{
public:
	virtual uint32_t get()=0;
	virtual uint32_t get_uniform(uint32_t upbound)=0;
};

class KeyRng : public Rng{
	uint8_t *key;
	int keylen;
	int idx;
	uint64_t state;

	void stir();

public:
	//throws invalid_argument if keylen<=0
	KeyRng(const char *key,int keylen);
	explicit KeyRng(const std::string &key);

	KeyRng(const Rng&)=delete; //just keep it at one KeyRng please
	~KeyRng();

	uint32_t get();
	uint32_t get_uniform(uint32_t upbound);
};

class CryptoRng : public Rng{
public:
	uint32_t get();
	uint32_t get_uniform(uint32_t upbound);
};