Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michael Walle | d96bd01 | 2012-06-05 11:33:14 +0000 | [diff] [blame] | 2 | /* |
| 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 Walle | d96bd01 | 2012-06-05 11:33:14 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | ecd1f81 | 2019-11-14 12:57:13 -0700 | [diff] [blame] | 11 | #include <rand.h> |
Michael Walle | d96bd01 | 2012-06-05 11:33:14 +0000 | [diff] [blame] | 12 | |
| 13 | static unsigned int y = 1U; |
| 14 | |
| 15 | unsigned 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 | |
| 24 | unsigned int rand(void) |
| 25 | { |
| 26 | return rand_r(&y); |
| 27 | } |
| 28 | |
| 29 | void srand(unsigned int seed) |
| 30 | { |
| 31 | y = seed; |
| 32 | } |