00001 // Copyright 2009-2015 Sandia Corporation. Under the terms 00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. 00003 // Government retains certain rights in this software. 00004 // 00005 // Copyright (c) 2009-2015, Sandia Corporation 00006 // All rights reserved. 00007 // 00008 // This file is part of the SST software package. For license 00009 // information, see the LICENSE file in the top level directory of the 00010 // distribution. 00011 00012 #ifndef SST_CORE_RNG_MERSENNE_H 00013 #define SST_CORE_RNG_MERSENNE_H 00014 00015 #include <stdint.h> 00016 #include <sys/time.h> 00017 00018 #include "sstrng.h" 00019 00020 #define MERSENNE_UINT32_MAX 4294967295U 00021 #define MERSENNE_UINT64_MAX 18446744073709551615ULL 00022 #define MERSENNE_INT32_MAX 2147483647L 00023 #define MERSENNE_INT64_MAX 9223372036854775807LL 00024 00025 namespace SST { 00026 namespace RNG { 00027 /** 00028 \class MersenneRNG mersenne.h "sst/core/rng/mersenne.h" 00029 00030 Implements a Mersenne-based RNG for use in the SST core or components. The Mersenne 00031 RNG provides a better "randomness" to the distribution of outputs but is computationally 00032 more expensive than the Marsaglia RNG. 00033 */ 00034 class MersenneRNG : public SSTRandom { 00035 00036 public: 00037 /** 00038 Create a new Mersenne RNG with a specified seed 00039 @param[in] seed The seed for this RNG 00040 */ 00041 MersenneRNG(unsigned int seed); 00042 00043 /** 00044 Creates a new Mersenne using a random seed which is obtained from the system 00045 clock. Note this will give different results on different platforms and between 00046 runs. 00047 */ 00048 MersenneRNG(); 00049 00050 /** 00051 Generates the next random number as a double value between 0 and 1. 00052 */ 00053 double nextUniform(); 00054 00055 /** 00056 Generates the next random number as an unsigned 32-bit integer 00057 */ 00058 uint32_t generateNextUInt32(); 00059 00060 /** 00061 Generates the next random number as an unsigned 64-bit integer 00062 */ 00063 uint64_t generateNextUInt64(); 00064 00065 /** 00066 Generates the next random number as a signed 64-bit integer 00067 */ 00068 int64_t generateNextInt64(); 00069 00070 /** 00071 Generates the next random number as a signed 32-bit integer 00072 */ 00073 int32_t generateNextInt32(); 00074 00075 /** 00076 Destructor for Mersenne 00077 */ 00078 ~MersenneRNG(); 00079 00080 private: 00081 /** 00082 Generates the next batch of random numbers 00083 */ 00084 void generateNextBatch(); 00085 00086 /** 00087 Stores the next set of random numbers 00088 */ 00089 uint32_t* numbers; 00090 00091 /** 00092 Tells us what index of the random number list the next returnable number should come from 00093 */ 00094 int index; 00095 00096 }; 00097 00098 } //namespace RNG 00099 } //namespace SST 00100 00101 #endif //SST_CORE_RNG_MERSENNE_H