2 * Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc, 465 S Mathlida Ave, Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
21 #include "simpleprng.h"
23 /* A *very* basic linear congruential generator; values are as cited in
24 * http://en.wikipedia.org/wiki/Linear_congruential_generator for Numerical Recipes */
31 simpleprng_state_t *state,
38 guint32 simpleprng_rand(
39 simpleprng_state_t *state)
41 return (*state = (A * (*state)) + C);
44 void simpleprng_fill_buffer(
45 simpleprng_state_t *state,
51 *(p++) = simpleprng_rand_byte(state);
55 gboolean simpleprng_verify_buffer(
56 simpleprng_state_t *state,
62 guint8 expected = simpleprng_rand_byte(state);
64 if (expected != got) {
66 "random value mismatch in buffer %p, offset %zd: got 0x%02x, expected 0x%02x\n",
67 buf, (size_t)(p-(guint8*)buf), (int)got, (int)expected);