2016-09-21 03:50:50 +02:00
|
|
|
//===- FuzzerRandom.h - Internal header for the Fuzzer ----------*- C++ -* ===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// fuzzer::Random
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_FUZZER_RANDOM_H
|
|
|
|
#define LLVM_FUZZER_RANDOM_H
|
|
|
|
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
namespace fuzzer {
|
2017-02-07 23:37:34 +01:00
|
|
|
class Random : public std::mt19937 {
|
2016-09-21 03:50:50 +02:00
|
|
|
public:
|
2017-02-07 23:37:34 +01:00
|
|
|
Random(unsigned int seed) : std::mt19937(seed) {}
|
|
|
|
result_type operator()() { return this->std::mt19937::operator()(); }
|
|
|
|
size_t Rand() { return this->operator()(); }
|
2016-09-21 03:50:50 +02:00
|
|
|
size_t RandBool() { return Rand() % 2; }
|
|
|
|
size_t operator()(size_t n) { return n ? Rand() % n : 0; }
|
2016-10-25 22:15:15 +02:00
|
|
|
intptr_t operator()(intptr_t From, intptr_t To) {
|
|
|
|
assert(From < To);
|
|
|
|
intptr_t RangeSize = To - From + 1;
|
|
|
|
return operator()(RangeSize) + From;
|
|
|
|
}
|
2016-09-21 03:50:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace fuzzer
|
|
|
|
|
|
|
|
#endif // LLVM_FUZZER_RANDOM_H
|