Exemple #1
0
// ShuffleN randomly shuffles the first n item in the data slice. It uses
// Knuth's shuffle algorithm. Panics if n is larger than data.Len()-1 or is
// negative.
func ShuffleN(data goutil.SwapInterface, n int) {
	if n < 0 {
		panic("ShuffleN with negative n")
	}
	if n > data.Len() {
		panic("ShuffleN n too large")
	}
	for i := 0; i < n; i++ {
		data.Swap(i, Rand(i, n))
	}
}
Exemple #2
0
// Shuffle randomly shuffles the all the item in the data slice.
func Shuffle(data goutil.SwapInterface) {
	ShuffleN(data, data.Len())
}