Skip to content

Improve default seed to spread out the entropy over all 3 words#11165

Open
RaimoNiskanen wants to merge 1 commit into
erlang:maintfrom
RaimoNiskanen:raimo/stdlib/rand-default-seed/OTP-20158
Open

Improve default seed to spread out the entropy over all 3 words#11165
RaimoNiskanen wants to merge 1 commit into
erlang:maintfrom
RaimoNiskanen:raimo/stdlib/rand-default-seed/OTP-20158

Conversation

@RaimoNiskanen
Copy link
Copy Markdown
Contributor

This fixes a spuriously failing test case for the exro928ss generator in the rand module, namely rand_SUITE:seed/1, on Windows.

The reason for these spurious failures stems from that the default seed is the 3 integers {erlang:phash2([{node(),self()]), erlang:system_time(), erlang:unique_integer()}.

For the exro928ss generator this makes the two first state words the same if the system time is the same for two calls. The third seed word and all subsequent will differ, though.

The test case in question tests that two successive seeds does not give the same random number sequence. But that is tested by simply checking if the first random value is the same. And for the exro928ss generator it is the second state word that determines the first generated number, so the first number will be the same (but not subsequent numbers).

The test case could be refined to check more numbers, but this PR does a hopefully better fix, which is to use MD5 to spread out the entropy of the same 3 values over all seed words. So even if it is just erlang:unique_integer() that differs between two seeds, about half of the bits in all seed words should differ.

This should minimize the probability to get the same value in any generator state word for any two default seeds.

@RaimoNiskanen RaimoNiskanen added this to the OTP-29.1 milestone Jun 1, 2026
@RaimoNiskanen RaimoNiskanen requested review from bjorng and dgud June 1, 2026 12:54
@RaimoNiskanen RaimoNiskanen self-assigned this Jun 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

CT Test Results

    2 files    100 suites   1h 6m 48s ⏱️
2 294 tests 2 243 ✅ 51 💤 0 ❌
2 714 runs  2 658 ✅ 56 💤 0 ❌

Results for commit a74b351.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@RaimoNiskanen RaimoNiskanen added team:PS Assigned to OTP team PS priority:low labels Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix priority:low team:PS Assigned to OTP team PS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants