Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/wasmfs/fuzzer/random.h
6175 views
1
// Copyright 2021 The Emscripten Authors. All rights reserved.
2
// Emscripten is available under two separate licenses, the MIT license and the
3
// University of Illinois/NCSA Open Source License. Both these licenses can be
4
// found in the LICENSE file.
5
6
// Original Source that was modified:
7
// https://github.com/WebAssembly/binaryen/blob/main/src/tools/fuzzing/random.h
8
9
#pragma once
10
11
#include <cstdint>
12
#include <map>
13
#include <set>
14
#include <string>
15
#include <vector>
16
17
namespace wasmfs {
18
19
class Random {
20
// The input seed bytes.
21
std::vector<char> bytes;
22
// The current position in `bytes`.
23
size_t pos = 0;
24
// Whether we already cycled through all the input (which might mean we should
25
// try to finish things off).
26
bool finishedInput = false;
27
// After we finish the input, we start going through it again, but xoring
28
// so it's not identical.
29
int xorFactor = 0;
30
31
public:
32
Random(std::vector<char>&& bytes) : bytes(std::move(bytes)){};
33
34
// Methods for getting random data.
35
int8_t get();
36
int16_t get16();
37
int32_t get32();
38
int64_t get64();
39
40
// Returns number in the range of [0,x).
41
uint32_t upTo(uint32_t x);
42
43
std::string getString(int8_t size);
44
std::string getSingleSymbolString(uint32_t length);
45
};
46
47
} // namespace wasmfs
48
49