Path: blob/main/system/lib/wasmfs/fuzzer/random.h
6175 views
// Copyright 2021 The Emscripten Authors. All rights reserved.1// Emscripten is available under two separate licenses, the MIT license and the2// University of Illinois/NCSA Open Source License. Both these licenses can be3// found in the LICENSE file.45// Original Source that was modified:6// https://github.com/WebAssembly/binaryen/blob/main/src/tools/fuzzing/random.h78#pragma once910#include <cstdint>11#include <map>12#include <set>13#include <string>14#include <vector>1516namespace wasmfs {1718class Random {19// The input seed bytes.20std::vector<char> bytes;21// The current position in `bytes`.22size_t pos = 0;23// Whether we already cycled through all the input (which might mean we should24// try to finish things off).25bool finishedInput = false;26// After we finish the input, we start going through it again, but xoring27// so it's not identical.28int xorFactor = 0;2930public:31Random(std::vector<char>&& bytes) : bytes(std::move(bytes)){};3233// Methods for getting random data.34int8_t get();35int16_t get16();36int32_t get32();37int64_t get64();3839// Returns number in the range of [0,x).40uint32_t upTo(uint32_t x);4142std::string getString(int8_t size);43std::string getSingleSymbolString(uint32_t length);44};4546} // namespace wasmfs474849