Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: src/IceRNG.h

Issue 455593004: Subzero: Add a random number generator. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/IceGlobalContext.cpp ('K') | « src/IceGlobalContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- subzero/src/IceRNG.h - Random number generator -----------*- C++ -*-===//
2 //
3 // The Subzero Code Generator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares a random number generator.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef SUBZERO_SRC_ICERNG_H
15 #define SUBZERO_SRC_ICERNG_H
16
17 #include <stdint.h>
18
19 namespace Ice {
20
21 // TODO: Replace with a cryptographically secure PRNG.
22 class RandomNumberGenerator {
23 public:
24 RandomNumberGenerator(uint64_t Seed) : State(Seed) {}
25
26 uint64_t next(uint64_t Bound) {
27 // Lewis, Goodman, and Miller (1969)
28 State = (16807 * State) % 2147483647;
29 return State % Bound;
30 }
31
32 private:
33 uint64_t State;
34 };
35
36 }
37
38 #endif // SUBZERO_SRC_ICERNG_H
OLDNEW
« src/IceGlobalContext.cpp ('K') | « src/IceGlobalContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698