Chromium Code Reviews| Index: lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp |
| diff --git a/lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp b/lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9557e2b39979038e27ed8d2873bdb8a9e76998f |
| --- /dev/null |
| +++ b/lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp |
| @@ -0,0 +1,42 @@ |
| +//===- NaClRandNumGen.cpp - Random number generator -------------*- C++ -*-===// |
|
jvoung (off chromium)
2015/06/01 17:26:35
no need for -*- C++ -*-
Karl
2015/06/01 22:40:54
Done.
|
| +// |
| +// The LLVM Compiler Infrastructure |
| +// |
| +// This file is distributed under the University of Illinois Open Source |
| +// License. See LICENSE.TXT for details. |
| +// |
| +//===----------------------------------------------------------------------===// |
| +// |
| +// This file provides a default implementation of a random number generator. |
|
jvoung (off chromium)
2015/06/01 17:26:35
//===---------------------------------------------
Karl
2015/06/01 22:40:55
Done.
|
| + |
| +#include "llvm/Bitcode/NaCl/NaClRandNumGen.h" |
| + |
| +#include <vector> |
| +#include <algorithm> |
| + |
| +namespace naclfuzz { |
| + |
| +// Put destructor in .cpp file go guarantee vtable construction. |
|
jvoung (off chromium)
2015/06/01 17:26:35
"go guarantee" -> "to guarantee"
Karl
2015/06/01 22:40:54
Done.
|
| +RandomNumberGenerator::~RandomNumberGenerator() {} |
| + |
| +DefaultRandomNumberGenerator::DefaultRandomNumberGenerator(std::string Seed) |
| + : Seed(Seed) { |
| + setSeed(0); |
|
jvoung (off chromium)
2015/06/01 17:26:35
How about call the method saltSeed() (can salt be
Karl
2015/06/01 22:40:54
Changed to saltSeed.
|
| +} |
| + |
| +uint64_t DefaultRandomNumberGenerator::operator()() { |
| + return Generator(); |
| +} |
| + |
| +void DefaultRandomNumberGenerator::setSeed(uint64_t Salt) { |
| + // Combine seed and salt and pass to generator. |
| + std::vector<uint32_t> Data; |
| + Data.reserve(Seed.size() + 2); |
| + Data.push_back(static_cast<uint32_t>(Salt)); |
| + Data.push_back(static_cast<uint32_t>(Salt >> 32)); |
| + std::copy(Seed.begin(), Seed.end(), Data.end()); |
| + std::seed_seq SeedSeq(Data.begin(), Data.end()); |
| + Generator.seed(SeedSeq); |
| +} |
| + |
| +} // end of namespace nacl |
|
jvoung (off chromium)
2015/06/01 17:26:35
naclfuzz
Karl
2015/06/01 22:40:55
Done.
|