@@ -12,24 +12,25 @@ public class RecursiveShuffler<T>
12
12
{
13
13
/// <summary>
14
14
/// First, it will check the length of the array on the base case.
15
- /// Next, if there's still element left, it will shuffle the sub-array.
16
- /// Lastly, it will randomly select index from 0 to length of array then
17
- /// swap the elements array[arrayLength ] and array[index].
15
+ /// Next, if there's still items left, it will shuffle the sub-array.
16
+ /// Lastly, it will randomly select index from 0 to number of items of the array
17
+ /// then swap the elements array[items ] and array[index].
18
18
/// </summary>
19
19
/// <param name="array">Array to shuffle.</param>
20
- /// <param name="arrayLength">The length of the array. Used for terminator .</param>
20
+ /// <param name="items">Number of items in the array .</param>
21
21
/// <param name="seed">Random generator seed. Used to repeat the shuffle.</param>
22
- public void Shuffle ( T [ ] array , int arrayLength , int ? seed = null )
22
+ public void Shuffle ( T [ ] array , int items , int ? seed = null )
23
23
{
24
- if ( arrayLength <= 0 )
24
+ if ( items <= 0 )
25
25
{
26
26
return ;
27
27
}
28
28
29
- Shuffle ( array , arrayLength - 1 , seed ) ;
29
+ Shuffle ( array , items - 1 , seed ) ;
30
30
var random = seed is null ? new Random ( ) : new Random ( seed . Value ) ;
31
- int index = random . Next ( arrayLength + 1 ) ;
32
- ( array [ arrayLength ] , array [ index ] ) = ( array [ index ] , array [ arrayLength ] ) ;
31
+ int index = random . Next ( items + 1 ) ;
32
+ ( array [ items ] , array [ index ] ) = ( array [ index ] , array [ items ] ) ;
33
+ ( array [ items ] , array [ index ] ) = ( array [ index ] , array [ items ] ) ;
33
34
}
34
35
}
35
36
}
0 commit comments