• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef FUZZERS_RANDOM_GENERATOR_ENGINE_H_
16 #define FUZZERS_RANDOM_GENERATOR_ENGINE_H_
17 
18 #include <memory>
19 #include <random>
20 #include <vector>
21 
22 namespace tint {
23 namespace fuzzers {
24 
25 /// Wrapper interface around STL random number engine
26 class RandomGeneratorEngine {
27  public:
28   RandomGeneratorEngine();
29   virtual ~RandomGeneratorEngine();
30   RandomGeneratorEngine(RandomGeneratorEngine&&);
31 
32   /// Generate random uint32_t value from uniform distribution.
33   /// @param lower - lower bound of integer generated
34   /// @param upper - upper bound of integer generated
35   /// @returns i, where lower <= i < upper
36   virtual uint32_t RandomUInt32(uint32_t lower, uint32_t upper) = 0;
37 
38   /// Get random uint64_t value from uniform distribution.
39   /// @param lower - lower bound of integer generated
40   /// @param upper - upper bound of integer generated
41   /// @returns i, where lower <= i < upper
42   virtual uint64_t RandomUInt64(uint64_t lower, uint64_t upper) = 0;
43 
44   /// Get N bytes of pseudo-random data
45   /// @param dest - memory location to store data
46   /// @param n - number of bytes of data to generate
47   virtual void RandomNBytes(uint8_t* dest, size_t n) = 0;
48 
49  private:
50   // Disallow copy & assign
51   RandomGeneratorEngine(const RandomGeneratorEngine&) = delete;
52   RandomGeneratorEngine& operator=(const RandomGeneratorEngine&) = delete;
53 };  // class RandomGeneratorEngine
54 
55 }  // namespace fuzzers
56 }  // namespace tint
57 
58 #endif  // FUZZERS_RANDOM_GENERATOR_ENGINE_H_
59