Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClRandNumGen.h

Issue 1156103003: Initial implementation of a record-level bitcode fuzzer. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@fuzz
Patch Set: Fix issues in last patch. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClFuzz.h ('k') | lib/Bitcode/NaCl/TestUtils/CMakeLists.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- NaClRandNumGen.h - random number generator ---------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a random number generator API for 64-bit unsigned
11 // values, and a corresponding default implementation.
12 //
13 // *** WARNING *** One should assume that random number generators are not
14 // thread safe.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_BITCODE_NACL_NACLRANDNUMGEN_H
19 #define LLVM_BITCODE_NACL_NACLRANDNUMGEN_H
20
21 #include "llvm/ADT/StringRef.h"
22 #include <random>
23
24 namespace naclfuzz {
25
26 /// Defines API for a random number generator to use with fuzzing.
27 class RandomNumberGenerator {
28 RandomNumberGenerator(const RandomNumberGenerator&) = delete;
29 void operator=(const RandomNumberGenerator&) = delete;
30 public:
31 virtual ~RandomNumberGenerator();
32 /// Returns a random number.
33 virtual uint64_t operator()() = 0;
34 // Returns a random value in [0..Limit)
35 uint64_t chooseInRange(uint64_t Limit) {
36 return (*this)() % Limit;
37 }
38 protected:
39 RandomNumberGenerator() {}
40 };
41
42 /// Defines a random number generator based on C++ generator std::mt19937_64.
43 class DefaultRandomNumberGenerator : public RandomNumberGenerator {
44 DefaultRandomNumberGenerator(const DefaultRandomNumberGenerator&) = delete;
45 void operator=(const DefaultRandomNumberGenerator&) = delete;
46 public:
47 DefaultRandomNumberGenerator(llvm::StringRef Seed);
48 uint64_t operator()() final;
49 ~DefaultRandomNumberGenerator() final {}
50 // Resets random number seed by salting the seed of constructor with Salt.
51 void saltSeed(uint64_t Salt);
52 private:
53 // 64-bit Mersenne Twister by Matsumoto and Nishimura, 2000
54 // http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
55 // This RNG is deterministically portable across C++11
56 // implementations.
57 std::mt19937_64 Generator;
58 // Seed for the random number generator.
59 std::string Seed;
60 };
61
62 } // end of namespace naclfuzz
63
64 #endif // LLVM_BITCODE_NACL_NACLRANDNUMGEN_H
OLDNEW
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClFuzz.h ('k') | lib/Bitcode/NaCl/TestUtils/CMakeLists.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698