Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.7k
Commitaaa2451
authored
MersenneTwister: simplify seeding logic (#60204)
Since at least v0.3, `MersenneTwister` has stored the user-providedseed. More recently, this allowed `show` to print a round-trippablerepresentation of the RNG. However, storing an arbitrary deep-copieduser seed is not ideal, and the initialization logic has become morecomplicated than necessary.In particular, `MersenneTwister()` currently performs three steps:1. `seed = rand(RandomDevice(), UInt128)` # generate a seed2. `initstate = rand(SeedHasher(seed), UInt32, 8)` # expand it3. initialize dSFMT with `initstate`This commit merges the first two steps. The new initialization is:1. `initstate = rand(RandomDevice(), NTuple{2, UInt128})`2. convert `initstate` to the dSFMT format and initialize the stateWe now store only `initstate` for use in `show`, preservinground-trippability. For user-provided seeds, `initstate` is derived fromthe seed via `SeedHasher`.A small bonus is that `MersenneTwister()` is no longer restricted to"only" 2^128 distinct initializations.The cosmetic drawback is that the printed representation is less pretty:`MersenneTwister(1)` now shows as```MersenneTwister(0xc53bc12f..., 0x50a4aa15...)```1 parent24d8ab5 commitaaa2451
2 files changed
+40
-77
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
92 | 93 | | |
| 94 | + | |
93 | 95 | | |
94 | | - | |
| 96 | + | |
95 | 97 | | |
96 | | - | |
97 | 98 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
| 99 | + | |
102 | 100 | | |
103 | 101 | | |
104 | 102 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 103 | + | |
| 104 | + | |
109 | 105 | | |
110 | 106 | | |
111 | 107 | | |
112 | 108 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 109 | + | |
117 | 110 | | |
118 | | - | |
| 111 | + | |
119 | 112 | | |
120 | 113 | | |
121 | 114 | | |
| |||
226 | 219 | | |
227 | 220 | | |
228 | 221 | | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
235 | 227 | | |
236 | 228 | | |
237 | 229 | | |
238 | 230 | | |
239 | 231 | | |
240 | 232 | | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 233 | + | |
| 234 | + | |
250 | 235 | | |
251 | 236 | | |
252 | 237 | | |
| |||
575 | 560 | | |
576 | 561 | | |
577 | 562 | | |
578 | | - | |
579 | | - | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
580 | 568 | | |
581 | | - | |
582 | | - | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
583 | 572 | | |
584 | | - | |
585 | | - | |
| 573 | + | |
| 574 | + | |
586 | 575 | | |
587 | 576 | | |
588 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
658 | | - | |
659 | | - | |
660 | | - | |
661 | 649 | | |
662 | 650 | | |
663 | 651 | | |
| |||
957 | 945 | | |
958 | 946 | | |
959 | 947 | | |
960 | | - | |
| 948 | + | |
| 949 | + | |
961 | 950 | | |
962 | | - | |
963 | | - | |
| 951 | + | |
| 952 | + | |
964 | 953 | | |
965 | | - | |
| 954 | + | |
966 | 955 | | |
967 | | - | |
| 956 | + | |
968 | 957 | | |
969 | | - | |
970 | | - | |
| 958 | + | |
| 959 | + | |
971 | 960 | | |
972 | 961 | | |
973 | | - | |
| 962 | + | |
974 | 963 | | |
975 | | - | |
976 | | - | |
| 964 | + | |
| 965 | + | |
977 | 966 | | |
978 | 967 | | |
979 | | - | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
| 968 | + | |
| 969 | + | |
996 | 970 | | |
997 | 971 | | |
998 | 972 | | |
| |||
0 commit comments
Comments
(0)