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_XORSHIFT_H 00013 #define SST_CORE_RNG_XORSHIFT_H 00014 00015 #include <stdint.h> 00016 #include <sys/time.h> 00017 00018 #include "sstrng.h" 00019 00020 #define XORSHIFT_UINT32_MAX 4294967295U 00021 #define XORSHIFT_UINT64_MAX 18446744073709551615ULL 00022 #define XORSHIFT_INT32_MAX 2147483647L 00023 #define XORSHIFT_INT64_MAX 9223372036854775807LL 00024 00025 namespace SST { 00026 namespace RNG { 00027 /** 00028 \class XORShiftRNG xorshift.h "sst/core/rng/xorshift.h" 00029 00030 Implements a lightweight RNG based on XOR-shift operations. We utilize the 00031 XORSHIFT algorithm from: http://en.wikipedia.org/wiki/Xorshift. This is a very 00032 lightweight and inexpensive RNG. 00033 00034 */ 00035 class XORShiftRNG : public SSTRandom { 00036 00037 public: 00038 /** 00039 Create a new Mersenne RNG with a specified seed 00040 @param[in] seed The seed for this RNG 00041 */ 00042 XORShiftRNG(unsigned int seed); 00043 00044 /** 00045 Creates a new Mersenne using a random seed which is obtained from the system 00046 clock. Note this will give different results on different platforms and between 00047 runs. 00048 */ 00049 XORShiftRNG(); 00050 00051 /** 00052 Generates the next random number as a double value between 0 and 1. 00053 */ 00054 double nextUniform(); 00055 00056 /** 00057 Generates the next random number as an unsigned 32-bit integer 00058 */ 00059 uint32_t generateNextUInt32(); 00060 00061 /** 00062 Generates the next random number as an unsigned 64-bit integer 00063 */ 00064 uint64_t generateNextUInt64(); 00065 00066 /** 00067 Generates the next random number as a signed 64-bit integer 00068 */ 00069 int64_t generateNextInt64(); 00070 00071 /** 00072 Generates the next random number as a signed 32-bit integer 00073 */ 00074 int32_t generateNextInt32(); 00075 00076 /** 00077 Destructor for Mersenne 00078 */ 00079 ~XORShiftRNG(); 00080 00081 protected: 00082 uint32_t x; 00083 uint32_t y; 00084 uint32_t z; 00085 uint32_t w; 00086 00087 }; 00088 00089 } //namespace RNG 00090 } //namespace SST 00091 00092 #endif //SST_CORE_RNG_XORSHIFT_H