Collections.Shuffle Method

Definition

Overloads

Shuffle(IList<Object>)

Randomly permutes the specified list using a default source of randomness.

Shuffle(IList<Object>, Random)

Randomly permute the specified list using the specified source of randomness.

Shuffle(IList<Object>)

Randomly permutes the specified list using a default source of randomness.

[Android.Runtime.Register("shuffle", "(Ljava/util/List;)V", "")]
public static void Shuffle (System.Collections.Generic.IList<object> list);
[<Android.Runtime.Register("shuffle", "(Ljava/util/List;)V", "")>]
static member Shuffle : System.Collections.Generic.IList<obj> -> unit

Parameters

list
IList<Object>

the list to be shuffled.

Attributes

Remarks

Randomly permutes the specified list using a default source of randomness. All permutations occur with approximately equal likelihood.

The hedge "approximately" is used in the foregoing description because default source of randomness is only approximately an unbiased source of independently chosen bits. If it were a perfect source of randomly chosen bits, then the algorithm would choose permutations with perfect uniformity.

This implementation traverses the list backwards, from the last element up to the second, repeatedly swapping a randomly selected element into the "current position". Elements are randomly selected from the portion of the list that runs from the first element to the current position, inclusive.

This method runs in linear time. If the specified list does not implement the RandomAccess interface and is large, this implementation dumps the specified list into an array before shuffling it, and dumps the shuffled array back into the list. This avoids the quadratic behavior that would result from shuffling a "sequential access" list in place.

Java documentation for java.util.Collections.shuffle(java.util.List<?>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

Shuffle(IList<Object>, Random)

Randomly permute the specified list using the specified source of randomness.

[Android.Runtime.Register("shuffle", "(Ljava/util/List;Ljava/util/Random;)V", "")]
public static void Shuffle (System.Collections.Generic.IList<object> list, Java.Util.Random rnd);
[<Android.Runtime.Register("shuffle", "(Ljava/util/List;Ljava/util/Random;)V", "")>]
static member Shuffle : System.Collections.Generic.IList<obj> * Java.Util.Random -> unit

Parameters

list
IList<Object>

the list to be shuffled.

rnd
Random

the source of randomness to use to shuffle the list.

Attributes

Remarks

Randomly permute the specified list using the specified source of randomness. All permutations occur with equal likelihood assuming that the source of randomness is fair.

This implementation traverses the list backwards, from the last element up to the second, repeatedly swapping a randomly selected element into the "current position". Elements are randomly selected from the portion of the list that runs from the first element to the current position, inclusive.

This method runs in linear time. If the specified list does not implement the RandomAccess interface and is large, this implementation dumps the specified list into an array before shuffling it, and dumps the shuffled array back into the list. This avoids the quadratic behavior that would result from shuffling a "sequential access" list in place.

Java documentation for java.util.Collections.shuffle(java.util.List<?>, java.util.Random).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to