2 * Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
27 /* A very simple, thread-safe PRNG. This is intended for use in generating
28 * reproducable bytestreams for testing purposes. It is *not*
29 * cryptographically secure! */
36 /* Initialize and seed the PRNG
38 * @param state: pointer to PRNG state
39 * @param seed: initial value
42 simpleprng_state_t *state,
45 /* Get a seed that will reproduce the PRNG's current state
47 * @param state: pointer to PRNG state
50 guint32 simpleprng_get_seed(
51 simpleprng_state_t *state);
53 /* Get a random guint32
55 * @param state: pointer to PRNG state
56 * @returns: random integer
58 guint32 simpleprng_rand(
59 simpleprng_state_t *state);
63 * @param state: pointer to PRNG state
64 * @returns: random integer
66 /* use the high-order bytes, as they're "more random" */
67 #define simpleprng_rand_byte(state) \
68 ((guint8)(simpleprng_rand((state)) >> 24))
70 /* Fill the given buffer with a sequence of bytes
72 * @param state: pointer to PRNG state
73 * @param buf: buffer to fill
74 * @param len: number of bytes to write
76 void simpleprng_fill_buffer(
77 simpleprng_state_t *state,
81 /* Verify that a buffer matches the values from the PRNG.
83 * @param state: pointer to PRNG state
84 * @param buf: buffer to verify
85 * @param len: number of bytes to verify
86 * @returns: true if all bytes match
88 gboolean simpleprng_verify_buffer(
89 simpleprng_state_t *state,
93 #endif /* SIMPLEPRNG_H */