1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "FuzzingTraits.h"
16 unsigned int FuzzingTraits::Random(unsigned int aMax
) {
17 MOZ_ASSERT(aMax
> 0, "aMax needs to be bigger than 0");
18 std::uniform_int_distribution
<unsigned int> d(0, aMax
);
23 bool FuzzingTraits::Sometimes(unsigned int aProbability
) {
24 return FuzzingTraits::Random(aProbability
) == 0;
28 size_t FuzzingTraits::Frequency(const size_t aSize
, const uint64_t aFactor
) {
29 return RandomIntegerRange
<size_t>(0, ceil(float(aSize
) / aFactor
)) + 1;
33 std::mt19937_64
& FuzzingTraits::Rng() {
34 static std::mt19937_64 rng
;
35 static std::once_flag flag
;
36 std::call_once(flag
, [&] { rng
.seed(PR_IntervalNow()); });
40 } // namespace fuzzing
41 } // namespace mozilla