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