SST  6.0.0
StructuralSimulationToolkit
xorshift.h
1 // Copyright 2009-2016 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2016, Sandia Corporation
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_RNG_XORSHIFT_H
13 #define SST_CORE_RNG_XORSHIFT_H
14 
15 #include <stdint.h>
16 #include <sys/time.h>
17 
18 #include "sstrng.h"
19 
20 #define XORSHIFT_UINT32_MAX 4294967295U
21 #define XORSHIFT_UINT64_MAX 18446744073709551615ULL
22 #define XORSHIFT_INT32_MAX 2147483647L
23 #define XORSHIFT_INT64_MAX 9223372036854775807LL
24 
25 namespace SST {
26 namespace RNG {
27 /**
28  \class XORShiftRNG xorshift.h "sst/core/rng/xorshift.h"
29 
30  Implements a lightweight RNG based on XOR-shift operations. We utilize the
31  XORSHIFT algorithm from: http://en.wikipedia.org/wiki/Xorshift. This is a very
32  lightweight and inexpensive RNG.
33 
34 */
35 class XORShiftRNG : public SSTRandom {
36 
37  public:
38  /**
39  Create a new Mersenne RNG with a specified seed
40  @param[in] seed The seed for this RNG
41  */
42  XORShiftRNG(unsigned int seed);
43 
44  /**
45  Creates a new Mersenne using a random seed which is obtained from the system
46  clock. Note this will give different results on different platforms and between
47  runs.
48  */
49  XORShiftRNG();
50 
51  /**
52  Generates the next random number as a double value between 0 and 1.
53  */
54  double nextUniform();
55 
56  /**
57  Generates the next random number as an unsigned 32-bit integer
58  */
59  uint32_t generateNextUInt32();
60 
61  /**
62  Generates the next random number as an unsigned 64-bit integer
63  */
64  uint64_t generateNextUInt64();
65 
66  /**
67  Generates the next random number as a signed 64-bit integer
68  */
69  int64_t generateNextInt64();
70 
71  /**
72  Generates the next random number as a signed 32-bit integer
73  */
74  int32_t generateNextInt32();
75 
76  /**
77  Seed the XOR RNG
78  */
79  void seed(uint64_t newSeed);
80 
81  /**
82  Destructor for Mersenne
83  */
84  ~XORShiftRNG();
85 
86 protected:
87  uint32_t x;
88  uint32_t y;
89  uint32_t z;
90  uint32_t w;
91 
92 };
93 
94 } //namespace RNG
95 } //namespace SST
96 
97 #endif //SST_CORE_RNG_XORSHIFT_H
int64_t generateNextInt64()
Generates the next random number as a signed 64-bit integer.
Definition: xorshift.cc:72
int32_t generateNextInt32()
Generates the next random number as a signed 32-bit integer.
Definition: xorshift.cc:92
XORShiftRNG()
Creates a new Mersenne using a random seed which is obtained from the system clock.
Definition: xorshift.cc:24
Definition: action.cc:17
void seed(uint64_t newSeed)
Seed the XOR RNG.
Definition: xorshift.cc:106
uint64_t generateNextUInt64()
Generates the next random number as an unsigned 64-bit integer.
Definition: xorshift.cc:58
~XORShiftRNG()
Destructor for Mersenne.
Definition: xorshift.cc:113
Implements the base class for random number generators for the SST core.
Definition: sstrng.h:27
Implements a lightweight RNG based on XOR-shift operations.
Definition: xorshift.h:35
uint32_t generateNextUInt32()
Generates the next random number as an unsigned 32-bit integer.
Definition: xorshift.cc:52
double nextUniform()
Generates the next random number as a double value between 0 and 1.
Definition: xorshift.cc:47