1 //===- FuzzerRandom.h - Internal header for the Fuzzer ----------*- C++ -* ===//
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
7 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
11 #ifndef LLVM_FUZZER_RANDOM_H
12 #define LLVM_FUZZER_RANDOM_H
17 class Random
: public std::minstd_rand
{
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
);
28 size_t operator()(size_t n
) { return n
? Rand() % n
: 0; }
29 intptr_t operator()(intptr_t From
, intptr_t To
) {
31 intptr_t RangeSize
= To
- From
+ 1;
32 return operator()(RangeSize
) + From
;
38 #endif // LLVM_FUZZER_RANDOM_H