//===--- Random.h - Utilities for random sampling -------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // Utilities for random sampling. // //===----------------------------------------------------------------------===// #ifndef LLVM_FUZZMUTATE_RANDOM_H #define LLVM_FUZZMUTATE_RANDOM_H #include "llvm/Support/raw_ostream.h" #include <random> namespace llvm { /// Return a uniformly distributed random value between \c Min and \c Max template <typename T, typename GenT> T uniform(GenT &Gen, T Min, T Max) { … } /// Return a uniformly distributed random value of type \c T template <typename T, typename GenT> T uniform(GenT &Gen) { … } /// Randomly selects an item by sampling into a set with an unknown number of /// elements, which may each be weighted to be more likely choices. template <typename T, typename GenT> class ReservoirSampler { … }; template <typename GenT, typename RangeT, typename ElT = std::remove_reference_t< decltype(*std::begin(std::declval<RangeT>()))>> ReservoirSampler<ElT, GenT> makeSampler(GenT &RandGen, RangeT &&Items) { … } template <typename GenT, typename T> ReservoirSampler<T, GenT> makeSampler(GenT &RandGen, const T &Item, uint64_t Weight) { … } template <typename T, typename GenT> ReservoirSampler<T, GenT> makeSampler(GenT &RandGen) { … } } // namespace llvm #endif // LLVM_FUZZMUTATE_RANDOM_H