Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Nov 27, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

Since at least v0.3, `MersenneTwister` has stored the user-provided
seed. More recently, this allowed `show` to print a round-trippable
representation of the RNG. However, storing an arbitrary deep-copied
user seed is not ideal, and the initialization logic has become more
complicated than necessary.

In particular, `MersenneTwister()` currently performs three steps:

1. `seed = rand(RandomDevice(), UInt128)`           # generate a seed
2. `initstate = rand(SeedHasher(seed), UInt32, 8)`  # expand it
3. 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 state

We now store only `initstate` for use in `show`, preserving
round-trippability. For user-provided seeds, `initstate` is derived from
the 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...)
```
@pull pull bot locked and limited conversation to collaborators Nov 27, 2025
@pull pull bot added the ⤵️ pull label Nov 27, 2025
@pull pull bot merged commit aaa2451 into MLH-Fellowship:master Nov 27, 2025
3 of 4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant