1 // Copyright 2005-2009 The RE2 Authors. All Rights Reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Modified from Google perftools's tcmalloc_unittest.cc.
7 #include "util/random.h"
11 int32
ACMRandom::Next() {
12 const int32 M
= 2147483647L; // 2^31-1
13 const int32 A
= 16807;
14 // In effect, we are computing seed_ = (seed_ * A) % M, where M = 2^31-1
15 uint32 lo
= A
* (int32
)(seed_
& 0xFFFF);
16 uint32 hi
= A
* (int32
)((uint32
)seed_
>> 16);
17 lo
+= (hi
& 0x7FFF) << 16;
27 return (seed_
= (int32
) lo
);
30 int32
ACMRandom::Uniform(int32 n
) {