@@ -66,10 +66,8 @@ impl ReseedingCore {
6666 #[ cold]
6767 #[ inline( never) ]
6868 fn try_to_reseed ( & mut self ) {
69- trace ! ( "Reseeding RNG (periodic reseed)" ) ;
70-
7169 if let Err ( e) = self . reseed ( ) {
72- warn ! ( "Reseeding RNG failed : {e}" ) ;
70+ panic ! ( "could not reseed ThreadRng : {e}" ) ;
7371 }
7472 }
7573}
@@ -105,7 +103,7 @@ impl ReseedingCore {
105103/// We leave it to the user to determine whether this generator meets their
106104/// security requirements. For an alternative, see [`SysRng`].
107105///
108- /// # Fork
106+ /// # Forks and interrupts
109107///
110108/// `ThreadRng` is not automatically reseeded on fork. It is recommended to
111109/// explicitly call [`ThreadRng::reseed`] immediately after a fork, for example:
@@ -123,7 +121,13 @@ impl ReseedingCore {
123121/// from an interrupt (e.g. a fork handler) unless it can be guaranteed that no
124122/// other method on the same `ThreadRng` is currently executing.
125123///
124+ /// # Panics
125+ ///
126+ /// Implementations of [`TryRng`] and [`Rng`] panic in case of [`SysRng`]
127+ /// failure during reseeding (highly unlikely).
128+ ///
126129/// [`StdRng`]: crate::rngs::StdRng
130+ /// [`Rng`]: rand_core::Rng
127131#[ derive( Clone ) ]
128132pub struct ThreadRng {
129133 // Rc is explicitly !Send and !Sync
@@ -190,6 +194,10 @@ thread_local!(
190194/// # Security
191195///
192196/// Refer to [`ThreadRng#Security`].
197+ ///
198+ /// # Panics
199+ ///
200+ /// This method panics in case of [`SysRng`] failure during initial seeding.
193201pub fn rng ( ) -> ThreadRng {
194202 let rng = THREAD_RNG_KEY . with ( |t| t. clone ( ) ) ;
195203 ThreadRng { rng }
0 commit comments