OLD | NEW |
1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===// | 1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file declares a random number generator. | 10 // This file declares a random number generator. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 public: | 46 public: |
47 uint64_t operator()(uint64_t Max) { return RNG.next(Max); } | 47 uint64_t operator()(uint64_t Max) { return RNG.next(Max); } |
48 bool getTrueWithProbability(float Probability); | 48 bool getTrueWithProbability(float Probability); |
49 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG) | 49 explicit RandomNumberGeneratorWrapper(RandomNumberGenerator &RNG) |
50 : RNG(RNG) {} | 50 : RNG(RNG) {} |
51 | 51 |
52 private: | 52 private: |
53 RandomNumberGenerator &RNG; | 53 RandomNumberGenerator &RNG; |
54 }; | 54 }; |
55 | 55 |
| 56 // RandomShuffle is an implementation of std::random_shuffle() that |
| 57 // doesn't change across stdlib implementations. Adapted from a |
| 58 // sample implementation at cppreference.com. |
| 59 template <class RandomIt, class RandomFunc> |
| 60 void RandomShuffle(RandomIt First, RandomIt Last, RandomFunc &&RNG) { |
| 61 for (auto i = Last - First - 1; i > 0; --i) |
| 62 std::swap(First[i], First[RNG(i + 1)]); |
| 63 } |
| 64 |
56 } // end of namespace Ice | 65 } // end of namespace Ice |
57 | 66 |
58 #endif // SUBZERO_SRC_ICERNG_H | 67 #endif // SUBZERO_SRC_ICERNG_H |
OLD | NEW |