/* DLIFE Copyright (C) 2000 Richard W.M. Jones * and other authors listed in the ``AUTHORS'' file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id: random.h,v 1.1 2002/04/05 14:40:28 rich Exp $ */ #ifndef random_h #define random_h #include "config.h" #include extern void random_init (void); /* Define this to run on a fault-free ``perfect'' CPU. (Use this * only when debugging). */ #define PERFECT_CPU 0 /* Return true 1 in PROBABILITY times. The argument PROBABILITY * is not limited to just powers of 2, but it must be an integer. */ extern inline int chance (unsigned probability) { #if !PERFECT_CPU return ((unsigned)random() % probability) == 0; #else return 0; #endif } /* Return 32 bits of randomness. */ extern inline unsigned get_rand_int () { return (unsigned)random(); } /* Return 16 bits of randomness. */ extern inline unsigned get_rand_short () { return (unsigned)random() & 0xffff; } /* Return 8 bits of randomness. */ extern inline unsigned get_rand_byte () { return (unsigned)random() & 0xff; } #endif /* random_h */