@@ -160,9 +160,7 @@ public static void SelectPermutationInplace<T>(T[] data, System.Random randomSou
160160 for ( int i = data . Length - 1 ; i > 0 ; i -- )
161161 {
162162 int swapIndex = random . Next ( i + 1 ) ;
163- T swap = data [ i ] ;
164- data [ i ] = data [ swapIndex ] ;
165- data [ swapIndex ] = swap ;
163+ ( data [ i ] , data [ swapIndex ] ) = ( data [ swapIndex ] , data [ i ] ) ;
166164 }
167165 }
168166
@@ -372,30 +370,36 @@ public static BigInteger[] GenerateVariation(BigInteger n, int k, System.Random
372370 if ( k > n ) throw new ArgumentOutOfRangeException ( nameof ( k ) , $ "k must be smaller than or equal to n.") ;
373371
374372 var random = randomSource ?? SystemRandomSource . Default ;
373+
375374 BigInteger [ ] selection = new BigInteger [ k ] ;
376375 if ( n == 0 || k == 0 )
376+ {
377377 return selection ;
378- selection [ 0 ] = random . NextBigIntegerSequence ( 0 , n ) . First ( ) ;
379- bool [ ] CompareCache ;
380- bool KeepLooping ;
381- BigInteger RandomNumber ;
378+ }
379+
380+ selection [ 0 ] = random . NextBigIntegerSequence ( BigInteger . Zero , n ) . First ( ) ;
381+ bool [ ] compareCache ;
382+ bool keepLooping ;
383+ BigInteger randomNumber ;
384+
382385 for ( int a = 1 ; a < k ; a ++ )
383386 {
384- RandomNumber = random . NextBigIntegerSequence ( 0 , n - a ) . First ( ) ;
385- CompareCache = Enumerable . Repeat ( true , a ) . ToArray ( ) ;
387+ randomNumber = random . NextBigIntegerSequence ( BigInteger . Zero , n - a ) . First ( ) ;
388+ compareCache = Generate . Repeat ( a , true ) ;
386389 do
387390 {
388- KeepLooping = false ;
391+ keepLooping = false ;
389392 for ( int b = 0 ; b < a ; ++ b )
390- if ( CompareCache [ b ] && RandomNumber >= selection [ b ] )
393+ if ( compareCache [ b ] && randomNumber >= selection [ b ] )
391394 {
392- CompareCache [ b ] = false ;
393- KeepLooping = true ;
394- RandomNumber ++ ;
395+ compareCache [ b ] = false ;
396+ keepLooping = true ;
397+ randomNumber ++ ;
395398 }
396- } while ( KeepLooping ) ;
397- selection [ a ] = RandomNumber ;
399+ } while ( keepLooping ) ;
400+ selection [ a ] = randomNumber ;
398401 }
402+
399403 return selection ;
400404 }
401405
0 commit comments