[DominatorTree] Add support for mixed pre/post CFG views.
[llvm-project.git] / compiler-rt / lib / fuzzer / FuzzerRandom.h
blob659283eee2074b43829ef7d7deecd5e90f7a9e94
1 //===- FuzzerRandom.h - Internal header for the Fuzzer ----------*- C++ -* ===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 // fuzzer::Random
9 //===----------------------------------------------------------------------===//
11 #ifndef LLVM_FUZZER_RANDOM_H
12 #define LLVM_FUZZER_RANDOM_H
14 #include <random>
16 namespace fuzzer {
17 class Random : public std::minstd_rand {
18 public:
19 Random(unsigned int seed) : std::minstd_rand(seed) {}
20 result_type operator()() { return this->std::minstd_rand::operator()(); }
21 size_t Rand() { return this->operator()(); }
22 size_t RandBool() { return Rand() % 2; }
23 size_t SkewTowardsLast(size_t n) {
24 size_t T = this->operator()(n * n);
25 size_t Res = sqrt(T);
26 return Res;
28 size_t operator()(size_t n) { return n ? Rand() % n : 0; }
29 intptr_t operator()(intptr_t From, intptr_t To) {
30 assert(From < To);
31 intptr_t RangeSize = To - From + 1;
32 return operator()(RangeSize) + From;
36 } // namespace fuzzer
38 #endif // LLVM_FUZZER_RANDOM_H