Skip to content

feat(random/unstable): allow generating seeded random bytes and 53-bit-entropy floats in [0, 1) #6626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lionel-rowe
Copy link
Contributor

Towards #6602

Currently, this doesn't change the existing randomSeeded, other than a tiny documentation change to indicate that it only provides 32 bits of entropy.

Instead, it adds:

  • byteGeneratorSeeded, which returns a ByteGenerator function, fulfilling the same contract as crypto.getRandomBytes (sans the non-u8 typed array signatures, which are probably best avoided due to their unspecified endianness).
  • nextFloat64, which takes a ByteGenerator function and uses it to get a float in [0, 1) with 53 bits of entropy.

Used together, the two functions can be used to get identical f64 sequences to the rust rand crate, given the same u64 seed. byteGeneratorSeeded can also be used by reading little-endian from appropriately sized Uint8Arrays to get identical sequences of various integer types (u8, i32, etc.) to the rust crate.

There's still an open question as to whether the 32-bit-entropy randomSeeded should be superseded by the 53-bit-entropy version, and if so what the upgrade path looks like for that.

@lionel-rowe lionel-rowe requested a review from kt3k as a code owner April 26, 2025 10:45
Copy link

codecov bot commented Apr 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.75%. Comparing base (f8894da) to head (6d31afb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6626   +/-   ##
=======================================
  Coverage   94.74%   94.75%           
=======================================
  Files         583      584    +1     
  Lines       46478    46525   +47     
  Branches     6523     6524    +1     
=======================================
+ Hits        44036    44083   +47     
  Misses       2399     2399           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant