-
Notifications
You must be signed in to change notification settings - Fork 2
/
randu.c
45 lines (33 loc) · 786 Bytes
/
randu.c
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
37
38
39
40
41
42
43
44
45
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <talloc.h>
#include "randu.h"
#include "rngod.h"
#include "rng-private.h"
struct rng_randu {
struct rngod rng;
uint32_t val;
};
static uint64_t
rngod_randu_method_rand(struct rngod *rng) {
struct rng_randu *rngr = talloc_get_type(rng, struct rng_randu);
rngr->val = ((rngr->val << 16) + (rngr->val << 1) + rngr->val) &
0x7fffffff;
return rngr->val;
}
struct rngod *
rngod_randu_add(uint32_t seed) {
struct rng_randu *rngr;
rngr = talloc(NULL, struct rng_randu);
if (!rngr) return NULL;
rngr->val = seed;
rngr->rng.rand = rngod_randu_method_rand;
default_init(&rngr->rng);
return &rngr->rng;
}
struct rngod *
rngod_randu_add_default(void) {
return rngod_randu_add(1);
}