1 /*
2  * Copyright (c) 2008-2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <rand.h>
9 #include <sys/types.h>
10 
11 static unsigned int randseed = 12345;
12 
srand(unsigned int seed)13 void srand(unsigned int seed) {
14     randseed = seed;
15 }
16 
rand_add_entropy(const void * buf,size_t len)17 void rand_add_entropy(const void *buf, size_t len) {
18     if (len == 0)
19         return;
20 
21     uint32_t enp = 0;
22     for (size_t i = 0; i < len; i++) {
23         uint32_t c = ((const uint8_t *)buf)[i];
24         enp = ((enp << 8) | (enp >> 24)) ^ c;
25     }
26 
27     randseed ^= enp;
28 }
29 
rand(void)30 int rand(void) {
31     return (randseed = randseed * 1664525 + 1013904223);
32 }
33