]> Git Repo - J-u-boot.git/blob - lib/rand.c
Merge git://git.denx.de/u-boot-sunxi
[J-u-boot.git] / lib / rand.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Simple xorshift PRNG
4  *   see http://www.jstatsoft.org/v08/i14/paper
5  *
6  * Copyright (c) 2012 Michael Walle
7  * Michael Walle <[email protected]>
8  */
9
10 #include <common.h>
11
12 static unsigned int y = 1U;
13
14 unsigned int rand_r(unsigned int *seedp)
15 {
16         *seedp ^= (*seedp << 13);
17         *seedp ^= (*seedp >> 17);
18         *seedp ^= (*seedp << 5);
19
20         return *seedp;
21 }
22
23 unsigned int rand(void)
24 {
25         return rand_r(&y);
26 }
27
28 void srand(unsigned int seed)
29 {
30         y = seed;
31 }
This page took 0.027387 seconds and 4 git commands to generate.