Chromium Code Reviews| Index: src/IceRNG.cpp |
| diff --git a/src/IceRNG.cpp b/src/IceRNG.cpp |
| index a6b9adf5b93bfb2b867ebc4ce3e84b33ec7a5e07..a106ffe157ffeaed573aae535dcd5ba5c29736b9 100644 |
| --- a/src/IceRNG.cpp |
| +++ b/src/IceRNG.cpp |
| @@ -30,7 +30,19 @@ constexpr unsigned MAX = 2147483647; |
| // attacker can't introspect. |
| RandomNumberGenerator::RandomNumberGenerator(uint64_t Seed, llvm::StringRef) |
| : State(Seed) {} |
| - |
| +/// Create a random number generator with: global seed, |
|
Jim Stichnoth
2015/08/19 19:03:04
The same comment/docstring appears in IceRNG.h and
qining
2015/08/19 23:25:49
Done. Removed the one in .cpp.
|
| +/// randomization pass ID and a salt uint64_t integer. |
| +/// @param Seed should be a global seed. |
| +/// @param RandomizationPassID should be one of RandomizationPassesEnum. |
| +/// @param Salt should be an additional integer input for generating unique RNG. |
| +/// Final seed = Seed ^ Salt << 16 ^ RandomizationPassID << 28 |
|
Jim Stichnoth
2015/08/19 19:03:04
I'd like to see an explanation of these magic shif
qining
2015/08/19 23:25:49
Done.
|
| +RandomNumberGenerator::RandomNumberGenerator( |
| + uint64_t Seed, RandomizationPassesEnum RandomizationPassID, uint64_t Salt) |
| + : State(Seed ^ Salt << 16 ^ RandomizationPassID << 28) { |
|
Jim Stichnoth
2015/08/19 19:03:04
Instead of 16 and 28 (or 48 and 60 in the proposed
qining
2015/08/19 23:25:49
It seems I have to put these constexpr and the ass
|
| + assert(RandomizationPassID < 0x10 && "RandomizationPassID requires more than " |
|
Jim Stichnoth
2015/08/19 19:03:04
Use a static_assert instead:
static_assert(blah
qining
2015/08/19 23:25:49
Done.
|
| + "4 bits, left shifting 28 bits causes " |
| + "overflow"); |
| +} |
| uint64_t RandomNumberGenerator::next(uint64_t Max) { |
| // Lewis, Goodman, and Miller (1969) |
| State = (16807 * State) % MAX; |