blob: 5c367e186f9d38b6bc82002cec1f81a6d4efa7c8 [file] [log] [blame]
Michael Walle9acf1ca2012-06-05 11:33:14 +00001/*
2 * Simple xorshift PRNG
3 * see http://www.jstatsoft.org/v08/i14/paper
4 *
5 * Copyright (c) 2012 Michael Walle
6 * Michael Walle <michael@walle.cc>
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Michael Walle9acf1ca2012-06-05 11:33:14 +00009 */
10
11#include <common.h>
12
13static unsigned int y = 1U;
14
15unsigned int rand_r(unsigned int *seedp)
16{
17 *seedp ^= (*seedp << 13);
18 *seedp ^= (*seedp >> 17);
19 *seedp ^= (*seedp << 5);
20
21 return *seedp;
22}
23
24unsigned int rand(void)
25{
26 return rand_r(&y);
27}
28
29void srand(unsigned int seed)
30{
31 y = seed;
32}