| OLD | NEW |
| 1 //===- subzero/src/IceRNG.cpp - PRNG implementation -----------------------===// | 1 //===- subzero/src/IceRNG.cpp - PRNG implementation -----------------------===// |
| 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 /// \file | 10 /// \file |
| 11 /// \brief Implements the random number generator. | 11 /// \brief Implements the random number generator. |
| 12 /// | 12 /// |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "IceRNG.h" | 15 #include "IceRNG.h" |
| 16 | 16 |
| 17 #include <climits> |
| 17 #include <ctime> | 18 #include <ctime> |
| 18 | 19 |
| 19 namespace Ice { | 20 namespace Ice { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 constexpr unsigned MAX = 2147483647; | 23 constexpr unsigned MAX = 2147483647; |
| 23 } // end of anonymous namespace | 24 } // end of anonymous namespace |
| 24 | 25 |
| 25 // TODO(wala,stichnot): Switch to RNG implementation from LLVM or C++11. | 26 // TODO(wala,stichnot): Switch to RNG implementation from LLVM or C++11. |
| 26 // | 27 // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 45 // Lewis, Goodman, and Miller (1969) | 46 // Lewis, Goodman, and Miller (1969) |
| 46 State = (16807 * State) % MAX; | 47 State = (16807 * State) % MAX; |
| 47 return State % Max; | 48 return State % Max; |
| 48 } | 49 } |
| 49 | 50 |
| 50 bool RandomNumberGeneratorWrapper::getTrueWithProbability(float Probability) { | 51 bool RandomNumberGeneratorWrapper::getTrueWithProbability(float Probability) { |
| 51 return RNG.next(MAX) < Probability * MAX; | 52 return RNG.next(MAX) < Probability * MAX; |
| 52 } | 53 } |
| 53 | 54 |
| 54 } // end of namespace Ice | 55 } // end of namespace Ice |
| OLD | NEW |