Kostya Serebryany | 6f5a804 | 2016-09-21 01:50:50 +0000 | [diff] [blame] | 1 | //===- FuzzerRandom.h - Internal header for the Fuzzer ----------*- 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 | // fuzzer::Random |
| 10 | //===----------------------------------------------------------------------===// |
| 11 | |
| 12 | #ifndef LLVM_FUZZER_RANDOM_H |
| 13 | #define LLVM_FUZZER_RANDOM_H |
| 14 | |
| 15 | #include <random> |
| 16 | |
| 17 | namespace fuzzer { |
| 18 | class Random { |
| 19 | public: |
| 20 | Random(unsigned int seed) : R(seed) {} |
| 21 | size_t Rand() { return R(); } |
| 22 | size_t RandBool() { return Rand() % 2; } |
| 23 | size_t operator()(size_t n) { return n ? Rand() % n : 0; } |
| 24 | std::mt19937 &Get_mt19937() { return R; } |
| 25 | private: |
| 26 | std::mt19937 R; |
| 27 | }; |
| 28 | |
| 29 | } // namespace fuzzer |
| 30 | |
| 31 | #endif // LLVM_FUZZER_RANDOM_H |