motoko-base icon indicating copy to clipboard operation
motoko-base copied to clipboard

Possible improvements for `Random`

Open rvanasa opened this issue 3 years ago • 5 comments

  • We could provide an asynchronous alternative to Random.Finite which automatically replenishes entropy by calling Random.blob(), since this would drastically reduce the complexity of random number generation for common use cases. That being said, it seems reasonable to also keep the current functionality due to the extra overhead from async calls.

rvanasa avatar Dec 22 '22 20:12 rvanasa

I think @ggreif deliberately didn't do that so people don't re-use stale entropy in subsequent rounds, which can be unsafe for some applications that rely on unpredictable randomness. Not sure that applies here, but might.

crusso avatar Jan 10 '23 12:01 crusso

If we provide something like that (or a seeded RNG) then I'd prefer to put such functionality into a LowSecurity (or such) submodule.

ggreif avatar Jan 10 '23 13:01 ggreif

Makes sense. It also seems reasonable to defer this functionality to a third-party library, similar to Rust's rand crate.

rvanasa avatar Jan 10 '23 15:01 rvanasa

Though it would be nice if Random.Finite took a byte iterator, not a finite, blob, so you could give it an infinite supply of bits generated on demand using a PRNG, say.

crusso avatar Jan 13 '23 14:01 crusso

Though it would be nice if Random.Finite took a byte iterator, not a finite, blob, so you could give it an infinite supply of bits generated on demand using a PRNG, say.

Then it should be named Random.Stream.

ggreif avatar Jan 13 '23 14:01 ggreif