1
|
|
|
package gotil |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"github.com/gotilty/gotil/internal" |
5
|
|
|
) |
6
|
|
|
|
7
|
|
|
// Shuffle returns a new array of shuffled values, using a version of the Fisher-Yates shuffle. |
8
|
|
|
// The default seed is time.Now().UnixNano() |
9
|
|
|
// To change seed use gotil.ShuffleSeed() |
10
|
|
|
// seed := time.Now().UnixNano() |
11
|
|
|
// seed := int64(58239238) |
12
|
|
|
// Seed you will get the same sequence of pseudorandom numbers |
13
|
|
|
// each time you run the program. |
14
|
|
|
// data := []int64{-100, -5, 30, 100} |
15
|
|
|
// newData, _ := Shuffle(data) |
16
|
|
|
// // Output: [-5 100 -100 30] |
17
|
|
|
func Shuffle(a interface{}) (interface{}, error) { |
18
|
|
|
return internal.Shuffle(a) |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
// ShuffleSeed returns a new array of shuffled values, using a version of the Fisher-Yates shuffle with given seed |
22
|
|
|
// To use randomize seed -> gotil.ShuffleSeed() |
23
|
|
|
// seed := time.Now().UnixNano() |
24
|
|
|
// // Seed you will get the same sequence of pseudorandom numbers |
25
|
|
|
// // each time you run the program. |
26
|
|
|
// data := []int64{-100, -5, 30, 100} |
27
|
|
|
// newData, _ := ShuffleSeed(data, seed) |
28
|
|
|
// // Output: [-5 100 -100 30] |
29
|
|
|
func ShuffleSeed(a interface{}, seed int64) (interface{}, error) { |
30
|
|
|
return internal.ShuffleSeed(a, seed) |
31
|
|
|
} |
32
|
|
|
|