LogCabin
Core/Random.h
Go to the documentation of this file.
00001 /* Copyright (c) 2012 Stanford University
00002  * Copyright (c) 2015 Diego Ongaro
00003  *
00004  * Permission to use, copy, modify, and distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
00009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
00011  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00013  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00014  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #include <cinttypes>
00018 
00019 #ifndef LOGCABIN_CORE_RANDOM_H
00020 #define LOGCABIN_CORE_RANDOM_H
00021 
00022 namespace LogCabin {
00023 namespace Core {
00024 
00025 /**
00026  * Thread-safe pseudo-random number generator.
00027  * \warning
00028  *      Don't call these functions from static initializers or you might run
00029  *      into the static initialization order fiasco.
00030  */
00031 namespace Random {
00032 
00033 /// Return one random byte.
00034 uint8_t random8();
00035 /// Return two random bytes.
00036 uint16_t random16();
00037 /// Return four random bytes.
00038 uint32_t random32();
00039 /// Return eight random bytes.
00040 uint64_t random64();
00041 /// Return a random floating point number between start and end, inclusive.
00042 double randomRangeDouble(double start, double end);
00043 /// Return a random integer between start and end, inclusive.
00044 uint64_t randomRange(uint64_t start, uint64_t end);
00045 
00046 
00047 } // namespace LogCabin::Core::Random
00048 
00049 } // namespace LogCabin::Core
00050 } // namespace LogCabin
00051 
00052 #endif /* LOGCABIN_CORE_RANDOM_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines