| Index: src/IceRNG.h
|
| diff --git a/src/IceRNG.h b/src/IceRNG.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fcc65fb1084f9cb11402debc1c02c1ec2c86e7a1
|
| --- /dev/null
|
| +++ b/src/IceRNG.h
|
| @@ -0,0 +1,38 @@
|
| +//===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===//
|
| +//
|
| +// The Subzero Code Generator
|
| +//
|
| +// This file is distributed under the University of Illinois Open Source
|
| +// License. See LICENSE.TXT for details.
|
| +//
|
| +//===----------------------------------------------------------------------===//
|
| +//
|
| +// This file declares a random number generator.
|
| +//
|
| +//===----------------------------------------------------------------------===//
|
| +
|
| +#ifndef SUBZERO_SRC_ICERNG_H
|
| +#define SUBZERO_SRC_ICERNG_H
|
| +
|
| +#include <stdint.h>
|
| +
|
| +namespace Ice {
|
| +
|
| +// TODO: Replace with a cryptographically secure PRNG.
|
| +class RandomNumberGenerator {
|
| +public:
|
| + RandomNumberGenerator(uint64_t Seed) : State(Seed) {}
|
| +
|
| + uint64_t next(uint64_t Bound) {
|
| + // Lewis, Goodman, and Miller (1969)
|
| + State = (16807 * State) % 2147483647;
|
| + return State % Bound;
|
| + }
|
| +
|
| +private:
|
| + uint64_t State;
|
| +};
|
| +
|
| +}
|
| +
|
| +#endif // SUBZERO_SRC_ICERNG_H
|
|
|