busybox: update to 1.23.2
[tomato.git] / release / src / router / busybox / shell / random.h
blobc4eb44c133bb836e4b6d30ba497639444f49610b
1 /* vi: set sw=4 ts=4: */
2 /*
3 * $RANDOM support.
5 * Copyright (C) 2009 Denys Vlasenko
7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */
9 #ifndef SHELL_RANDOM_H
10 #define SHELL_RANDOM_H 1
12 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
14 typedef struct random_t {
15 /* State of random number generators: */
17 /* Galois LFSR (fast but weak) */
18 int32_t galois_LFSR; /* must be signed! */
20 /* LCG (fast but weak) */
21 uint32_t LCG;
23 /* 64-bit xorshift (fast, moderate strength) */
24 uint32_t xs64_x;
25 uint32_t xs64_y;
26 } random_t;
28 #define UNINITED_RANDOM_T(rnd) \
29 ((rnd)->galois_LFSR == 0)
31 #define INIT_RANDOM_T(rnd, nonzero, v) \
32 ((rnd)->galois_LFSR = (rnd)->xs64_x = (nonzero), (rnd)->LCG = (rnd)->xs64_y = (v))
34 #define CLEAR_RANDOM_T(rnd) \
35 ((rnd)->galois_LFSR = 0)
37 uint32_t next_random(random_t *rnd) FAST_FUNC;
39 POP_SAVED_FUNCTION_VISIBILITY
41 #endif