2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 // Helper functions for random number generation.
10 #ifndef UTIL_RANDOM_UTILS_H
11 #define UTIL_RANDOM_UTILS_H
13 // TODO(jmadill): Rework this if Chromium decides to ban <random>
21 class ANGLE_EXPORT RNG
26 // Seed from fixed number.
27 RNG(unsigned int seed);
30 void reseed(unsigned int newSeed);
33 int randomIntBetween(int min, int max);
34 unsigned int randomUInt();
36 float randomFloatBetween(float min, float max);
37 float randomNegativeOneToOne();
40 std::default_random_engine mGenerator;
43 // Implemented inline to avoid cross-module allocation issues.
44 inline void FillVectorWithRandomUBytes(RNG *rng, std::vector<uint8_t> *data)
46 for (size_t i = 0; i < data->size(); ++i)
48 (*data)[i] = static_cast<uint8_t>(rng->randomIntBetween(0, 255));
52 inline void FillVectorWithRandomUBytes(std::vector<uint8_t> *data)
55 FillVectorWithRandomUBytes(&rng, data);
60 #endif // UTIL_RANDOM_UTILS_H