OLD | NEW |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 #ifndef SRC_SHARED_RANDOM_H_ | 5 #ifndef SRC_SHARED_RANDOM_H_ |
6 #define SRC_SHARED_RANDOM_H_ | 6 #define SRC_SHARED_RANDOM_H_ |
7 | 7 |
8 #include "src/shared/globals.h" | 8 #include "src/shared/globals.h" |
9 | 9 |
10 namespace fletch { | 10 namespace dartino { |
11 | 11 |
12 // This class implements Xorshift+ | 12 // This class implements Xorshift+ |
13 // | 13 // |
14 // It has the following properties: | 14 // It has the following properties: |
15 // - it has 128-bit state | 15 // - it has 128-bit state |
16 // - it is guaranteed to cycle through every possible 128-bit state (except 0). | 16 // - it is guaranteed to cycle through every possible 128-bit state (except 0). |
17 // - it doesn't systematically fail the BigCrush tests. | 17 // - it doesn't systematically fail the BigCrush tests. |
18 // - on Intel hardware it is slightly faster than Xorshift* and LCG generators. | 18 // - on Intel hardware it is slightly faster than Xorshift* and LCG generators. |
19 // - it doesn't need multiply instructions. Note that the Cortex M0/M1 has | 19 // - it doesn't need multiply instructions. Note that the Cortex M0/M1 has |
20 // only 32x32->32 bit multiply, no 32x32->64 bit mul instruction. | 20 // only 32x32->32 bit multiply, no 32x32->64 bit mul instruction. |
(...skipping 15 matching lines...) Expand all Loading... |
36 x ^= y ^ (y >> 26); | 36 x ^= y ^ (y >> 26); |
37 s1_ = x; | 37 s1_ = x; |
38 return x + y; | 38 return x + y; |
39 } | 39 } |
40 | 40 |
41 private: | 41 private: |
42 uint64 s0_; | 42 uint64 s0_; |
43 uint64 s1_; | 43 uint64 s1_; |
44 }; | 44 }; |
45 | 45 |
46 } // namespace fletch | 46 } // namespace dartino |
47 | 47 |
48 #endif // SRC_SHARED_RANDOM_H_ | 48 #endif // SRC_SHARED_RANDOM_H_ |
OLD | NEW |