blob: d6f2977e8dcc8083940a7f2e1ca26860e5affab2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michael Walle9acf1ca2012-06-05 11:33:14 +00002/*
3 * Simple xorshift PRNG
4 * see http://www.jstatsoft.org/v08/i14/paper
5 *
6 * Copyright (c) 2012 Michael Walle
7 * Michael Walle <michael@walle.cc>
Michael Walle9acf1ca2012-06-05 11:33:14 +00008 */
9
Simon Glass840ef4d2019-11-14 12:57:13 -070010#include <rand.h>
Michael Walle9acf1ca2012-06-05 11:33:14 +000011
12static unsigned int y = 1U;
13
14unsigned 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
23unsigned int rand(void)
24{
25 return rand_r(&y);
26}
27
28void srand(unsigned int seed)
29{
30 y = seed;
31}