Base Framework
Random.h
1 /***************************************************************************
2  The Base Framework
3  A framework for developing platform independent applications
4 
5  See COPYRIGHT.txt for details.
6 
7  This framework is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11  For the licensing terms refer to the file 'LICENSE'.
12  ***************************************************************************/
13 
14 #pragma once
15 
16 #include <base/concurrency/SpinLock.h>
17 
18 _COM_AZURE_DEV__BASE__ENTER_NAMESPACE
19 
20 namespace RandomImpl {
21 
22  template<unsigned int ID>
23  class Traits {
24  };
25 
26 };
27 
39 // TAG: rename
40 class _COM_AZURE_DEV__BASE__API RandomLegacy {
41  friend class Initialization;
42 public:
43 
45  enum Generator {MT11213A = 0, MT11213B = 1, MT19937 = 2, TT800 = 3};
48 private:
49 
51  static unsigned int state[];
53  static unsigned int nextWord;
55  static SpinLock spinLock;
56 public:
57 
61  static void randomize() noexcept;
62 
68  static void randomize(unsigned int seed) noexcept;
69 
73  static unsigned int getInteger() noexcept;
74 
78  static inline float getFloat() noexcept {
79  return static_cast<float>((1.0/0xffffffff) * getInteger());
80  }
81 
85  static inline double getDouble() noexcept {
86  return (1.0/0xffffffff) * getInteger();
87  }
88 
92  static inline long double getLongDouble() noexcept {
93  return (1.0L/0xffffffff) * getInteger();
94  }
95 };
96 
97 _COM_AZURE_DEV__BASE__LEAVE_NAMESPACE
RandomLegacy::Traits
RandomImpl::Traits< TT800 > Traits
Definition: Random.h:47
RandomImpl::Traits
Definition: Random.h:34
RandomLegacy
Random number generator.
Definition: Random.h:40
RandomLegacy::getDouble
static double getDouble() noexcept
Definition: Random.h:85
RandomLegacy::getLongDouble
static long double getLongDouble() noexcept
Definition: Random.h:92
RandomLegacy::Generator
Generator
Definition: Random.h:45
SpinLock
Spin lock (fast).
Definition: SpinLock.h:32