Hash :
f83cbc65
Author :
Date :
2016-01-22T15:27:21
Use std::random functions for test and samples RNG. These standard functions are much more powerful than the C random() routines. Use them to improve the random utils, and use a class to clean things up further. This fixes a problem I was having using random_utils where I was having trouble generating random 32 bit unsigned integers. BUG=angleproject:1290 Change-Id: I5081764053d0667a4e323553b7dea531256aa778 Reviewed-on: https://chromium-review.googlesource.com/323440 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// random_utils:
// Helper functions for random number generation.
//
#ifndef UTIL_RANDOM_UTILS_H
#define UTIL_RANDOM_UTILS_H
// TODO(jmadill): Rework this if Chromium decides to ban <random>
#include <random>
namespace angle
{
class RNG
{
public:
// Seed from clock
RNG();
// Seed from fixed number.
RNG(unsigned int seed);
~RNG();
void reseed(unsigned int newSeed);
int randomInt();
int randomIntBetween(int min, int max);
unsigned int randomUInt();
float randomFloat();
float randomFloatBetween(float min, float max);
float randomNegativeOneToOne();
private:
std::default_random_engine mGenerator;
};
} // namespace angle
#endif // UTIL_RANDOM_UTILS_H