1*a466cc55SCy Schubert /* 2*a466cc55SCy Schubert * Copyright (C) 2004-2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3*a466cc55SCy Schubert * Copyright (C) 1999-2001 Internet Software Consortium. 4*a466cc55SCy Schubert * 5*a466cc55SCy Schubert * Permission to use, copy, modify, and/or distribute this software for any 6*a466cc55SCy Schubert * purpose with or without fee is hereby granted, provided that the above 7*a466cc55SCy Schubert * copyright notice and this permission notice appear in all copies. 8*a466cc55SCy Schubert * 9*a466cc55SCy Schubert * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10*a466cc55SCy Schubert * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11*a466cc55SCy Schubert * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12*a466cc55SCy Schubert * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13*a466cc55SCy Schubert * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14*a466cc55SCy Schubert * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15*a466cc55SCy Schubert * PERFORMANCE OF THIS SOFTWARE. 16*a466cc55SCy Schubert */ 17*a466cc55SCy Schubert 18*a466cc55SCy Schubert /* $Id: random.h,v 1.20 2009/01/17 23:47:43 tbox Exp $ */ 19*a466cc55SCy Schubert 20*a466cc55SCy Schubert #ifndef ISC_RANDOM_H 21*a466cc55SCy Schubert #define ISC_RANDOM_H 1 22*a466cc55SCy Schubert 23*a466cc55SCy Schubert #include <isc/lang.h> 24*a466cc55SCy Schubert #include <isc/types.h> 25*a466cc55SCy Schubert 26*a466cc55SCy Schubert /*! \file isc/random.h 27*a466cc55SCy Schubert * \brief Implements a random state pool which will let the caller return a 28*a466cc55SCy Schubert * series of possibly non-reproducible random values. 29*a466cc55SCy Schubert * 30*a466cc55SCy Schubert * Note that the 31*a466cc55SCy Schubert * strength of these numbers is not all that high, and should not be 32*a466cc55SCy Schubert * used in cryptography functions. It is useful for jittering values 33*a466cc55SCy Schubert * a bit here and there, such as timeouts, etc. 34*a466cc55SCy Schubert */ 35*a466cc55SCy Schubert 36*a466cc55SCy Schubert ISC_LANG_BEGINDECLS 37*a466cc55SCy Schubert 38*a466cc55SCy Schubert void 39*a466cc55SCy Schubert isc_random_seed(isc_uint32_t seed); 40*a466cc55SCy Schubert /*%< 41*a466cc55SCy Schubert * Set the initial seed of the random state. 42*a466cc55SCy Schubert */ 43*a466cc55SCy Schubert 44*a466cc55SCy Schubert void 45*a466cc55SCy Schubert isc_random_get(isc_uint32_t *val); 46*a466cc55SCy Schubert /*%< 47*a466cc55SCy Schubert * Get a random value. 48*a466cc55SCy Schubert * 49*a466cc55SCy Schubert * Requires: 50*a466cc55SCy Schubert * val != NULL. 51*a466cc55SCy Schubert */ 52*a466cc55SCy Schubert 53*a466cc55SCy Schubert isc_uint32_t 54*a466cc55SCy Schubert isc_random_jitter(isc_uint32_t max, isc_uint32_t jitter); 55*a466cc55SCy Schubert /*%< 56*a466cc55SCy Schubert * Get a random value between (max - jitter) and (max). 57*a466cc55SCy Schubert * This is useful for jittering timer values. 58*a466cc55SCy Schubert */ 59*a466cc55SCy Schubert 60*a466cc55SCy Schubert ISC_LANG_ENDDECLS 61*a466cc55SCy Schubert 62*a466cc55SCy Schubert #endif /* ISC_RANDOM_H */ 63