1 /* DLIFE Copyright (C) 2000 Richard W.M. Jones <rich@annexia.org>
2 * and other authors listed in the ``AUTHORS'' file.
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,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * $Id: random.h,v 1.1 2002/04/05 14:40:28 rich Exp $
28 extern void random_init (void);
30 /* Define this to run on a fault-free ``perfect'' CPU. (Use this
31 * only when debugging).
35 /* Return true 1 in PROBABILITY times. The argument PROBABILITY
36 * is not limited to just powers of 2, but it must be an integer.
39 chance (unsigned probability)
42 return ((unsigned)random() % probability) == 0;
48 /* Return 32 bits of randomness. */
49 extern inline unsigned
52 return (unsigned)random();
55 /* Return 16 bits of randomness. */
56 extern inline unsigned
59 return (unsigned)random() & 0xffff;
62 /* Return 8 bits of randomness. */
63 extern inline unsigned
66 return (unsigned)random() & 0xff;