feat(random/unstable): allow generating seeded random bytes and 53-bit-entropy floats in [0, 1) #6626
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aByteGenerator
function, fulfilling the same contract ascrypto.getRandomBytes
(sans the non-u8 typed array signatures, which are probably best avoided due to their unspecified endianness).nextFloat64
, which takes aByteGenerator
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 sizedUint8Array
s 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.