"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/isc/include/isc/random.h" (4 Sep 2020, 1485 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "random.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 #pragma once
   13 
   14 #include <inttypes.h>
   15 #include <stdlib.h>
   16 
   17 #include <isc/lang.h>
   18 #include <isc/types.h>
   19 
   20 /*! \file isc/random.h
   21  * \brief Implements wrapper around a non-cryptographically secure
   22  * pseudo-random number generator.
   23  *
   24  */
   25 
   26 ISC_LANG_BEGINDECLS
   27 
   28 uint8_t
   29 isc_random8(void);
   30 /*!<
   31  * \brief Returns a single 8-bit random value.
   32  */
   33 
   34 uint16_t
   35 isc_random16(void);
   36 /*!<
   37  * \brief Returns a single 16-bit random value.
   38  */
   39 
   40 uint32_t
   41 isc_random32(void);
   42 /*!<
   43  * \brief Returns a single 32-bit random value.
   44  */
   45 
   46 void
   47 isc_random_buf(void *buf, size_t buflen);
   48 /*!<
   49  * \brief Fills the region buf of length buflen with random data.
   50  */
   51 
   52 uint32_t
   53 isc_random_uniform(uint32_t upper_bound);
   54 /*!<
   55  * \brief Will return a single 32-bit value, uniformly distributed but
   56  *        less than upper_bound.  This is recommended over
   57  *        constructions like ``isc_random() % upper_bound'' as it
   58  *        avoids "modulo bias" when the upper bound is not a power of
   59  *        two.  In the worst case, this function may require multiple
   60  *        iterations to ensure uniformity.
   61  */
   62 
   63 ISC_LANG_ENDDECLS