From 4c947984d64ae63a71c5441082a35309b9198fbf Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Wed, 9 Jul 2025 13:42:18 -0700 Subject: [PATCH] random: Add comment on `RandomSource::fill_bytes` about multiple calls This allows efficient implementations for random sources that generate a word at a time. --- library/core/src/random.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/random.rs b/library/core/src/random.rs index 051fe2608638..40338c3f4ac7 100644 --- a/library/core/src/random.rs +++ b/library/core/src/random.rs @@ -7,6 +7,11 @@ #[unstable(feature = "random", issue = "130703")] pub trait RandomSource { /// Fills `bytes` with random bytes. + /// + /// Note that calling `fill_bytes` multiple times is not equivalent to calling `fill_bytes` once + /// with a larger buffer. A `RandomSource` is allowed to return different bytes for those two + /// cases. For instance, this allows a `RandomSource` to generate a word at a time and throw + /// part of it away if not needed. fn fill_bytes(&mut self, bytes: &mut [u8]); }