pseudo_random_generator.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2019 Google LLC
  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. #ifndef SOURCE_FUZZ_PSEUDO_RANDOM_GENERATOR_H_
  15. #define SOURCE_FUZZ_PSEUDO_RANDOM_GENERATOR_H_
  16. #include <random>
  17. #include "source/fuzz/random_generator.h"
  18. namespace spvtools {
  19. namespace fuzz {
  20. // Generates random data from a pseudo-random number generator.
  21. class PseudoRandomGenerator : public RandomGenerator {
  22. public:
  23. explicit PseudoRandomGenerator(uint32_t seed);
  24. ~PseudoRandomGenerator() override;
  25. uint32_t RandomUint32(uint32_t bound) override;
  26. uint64_t RandomUint64(uint64_t bound) override;
  27. uint32_t RandomPercentage() override;
  28. bool RandomBool() override;
  29. double RandomDouble() override;
  30. private:
  31. std::mt19937 mt_;
  32. };
  33. } // namespace fuzz
  34. } // namespace spvtools
  35. #endif // SOURCE_FUZZ_PSEUDO_RANDOM_GENERATOR_H_