Deleted Added
full compact
random.c (110280) random.c (110321)
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 21 unchanged lines hidden (view full) ---

30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#if defined(LIBC_SCCS) && !defined(lint)
35static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95";
36#endif /* LIBC_SCCS and not lint */
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/lib/libc/stdlib/random.c 110280 2003-02-03 10:22:12Z ache $");
38__FBSDID("$FreeBSD: head/lib/libc/stdlib/random.c 110321 2003-02-04 11:24:08Z ache $");
39
40#include "namespace.h"
41#include <sys/time.h> /* for srandomdev() */
42#include <fcntl.h> /* for srandomdev() */
43#include <stdio.h>
44#include <stdlib.h>
45#include <unistd.h> /* for srandomdev() */
46#include "un-namespace.h"

--- 90 unchanged lines hidden (view full) ---

137#define SEP_4 1
138
139/*
140 * Array versions of the above information to make code run faster --
141 * relies on fact that TYPE_i == i.
142 */
143#define MAX_TYPES 5 /* max number of types above */
144
39
40#include "namespace.h"
41#include <sys/time.h> /* for srandomdev() */
42#include <fcntl.h> /* for srandomdev() */
43#include <stdio.h>
44#include <stdlib.h>
45#include <unistd.h> /* for srandomdev() */
46#include "un-namespace.h"

--- 90 unchanged lines hidden (view full) ---

137#define SEP_4 1
138
139/*
140 * Array versions of the above information to make code run faster --
141 * relies on fact that TYPE_i == i.
142 */
143#define MAX_TYPES 5 /* max number of types above */
144
145#define NSHUFF 100 /* to drop part of seed -> 1st value correlation */
146
145static long degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
146static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
147
148/*
149 * Initially, everything is set up as if from:
150 *
151 * initstate(1, randtbl, 128);
152 *

--- 106 unchanged lines hidden (view full) ---

259 * information a given number of times to get rid of any initial dependencies
260 * introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
261 * for default usage relies on values produced by this routine.
262 */
263void
264srandom(x)
265 unsigned long x;
266{
147static long degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
148static long seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
149
150/*
151 * Initially, everything is set up as if from:
152 *
153 * initstate(1, randtbl, 128);
154 *

--- 106 unchanged lines hidden (view full) ---

261 * information a given number of times to get rid of any initial dependencies
262 * introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
263 * for default usage relies on values produced by this routine.
264 */
265void
266srandom(x)
267 unsigned long x;
268{
267 long i;
269 long i, lim;
268
270
271 state[0] = x;
269 if (rand_type == TYPE_0)
272 if (rand_type == TYPE_0)
270 state[0] = x;
273 lim = NSHUFF;
271 else {
274 else {
272 state[0] = x;
273 for (i = 1; i < rand_deg; i++)
274 state[i] = good_rand(state[i - 1]);
275 fptr = &state[rand_sep];
276 rptr = &state[0];
275 for (i = 1; i < rand_deg; i++)
276 state[i] = good_rand(state[i - 1]);
277 fptr = &state[rand_sep];
278 rptr = &state[0];
277 for (i = 0; i < 10 * rand_deg; i++)
278 (void)random();
279 lim = 10 * rand_deg;
279 }
280 }
281 for (i = 0; i < lim; i++)
282 (void)random();
280}
281
282/*
283 * srandomdev:
284 *
285 * Many programs choose the seed value in a totally predictable manner.
286 * This often causes problems. We seed the generator using the much more
287 * secure random(4) interface. Note that this particular seeding

--- 211 unchanged lines hidden ---
283}
284
285/*
286 * srandomdev:
287 *
288 * Many programs choose the seed value in a totally predictable manner.
289 * This often causes problems. We seed the generator using the much more
290 * secure random(4) interface. Note that this particular seeding

--- 211 unchanged lines hidden ---