This is a creation in Article, where the information may have evolved or changed.
Array random order
Method 1.sliceOutOfOrder designates random number R to Exchange subscript R and Bottom I, I –, is the current last exchange
Method 2.rand.perm (array length) assigns the original array subscript to another array according to the random data
PackageMainImport "FMT"Import "Math/rand"Import "Time"var (rr = rand. New (Rand. Newsource (time. Now (). Unixnano ())) A1 = [2]int{} A2 = [Ten]int{}) Func main () {a: = []int{0,1} forI: =0; I <10000; i++ {Randslice ()//fmt. PRINTLN (RR. INTN (Ten))Sliceoutoforder (A)} FMT. PRINTLN (A1) Fmt. PRINTLN (A2)}func Sliceoutoforder (inch[]int) []int{L: = Len (inch) forI: = L-1; i >0; i--{r: = RR. INTN (i)inch[R],inch[I] =inch[I],inch[R]} a1[inch[0]] +=1 return inch}func Randslice () {inch: = RR. Perm (Ten) a2[inch[0]] +=1}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.