File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -137,6 +137,20 @@ public void ThreadSafeSample()
137137 t2 . Join ( ) ;
138138 }
139139
140+ /// <summary>
141+ /// NextBytes fills buffers of different sizes without throwing an exception (e.g. OutOfRangeException)
142+ /// </remarks>
143+ [ Test ]
144+ public void NextBytesDoesNotThrow ( )
145+ {
146+ var rng = ( System . Random ) Activator . CreateInstance ( _randomType , new object [ ] { false } ) ;
147+
148+ for ( int i = 1 ; i < 30 ; i ++ )
149+ {
150+ Assert . DoesNotThrow ( ( ) => rng . NextBytes ( new byte [ i ] ) ) ;
151+ }
152+ }
153+
140154 /// <summary>
141155 /// Test runner function.
142156 /// </summary>
Original file line number Diff line number Diff line change @@ -158,7 +158,8 @@ protected override void DoSampleBytes(byte[] buffer)
158158 int i = 0 ;
159159
160160 // Fill up the bulk of the buffer in chunks of 8 bytes at a time.
161- for ( int bound = buffer . Length - 3 ; i < bound ; )
161+ int bound = buffer . Length - ( buffer . Length % 8 ) ;
162+ while ( i < bound )
162163 {
163164 // Generate 64 random bits.
164165 ulong x = RotateLeft ( s1 * 5 , 7 ) * 9 ;
You can’t perform that action at this time.
0 commit comments