Passed
Pull Request — master (#66)
by Hayrullah
56s
created

shuffle.go   A

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A gotil.Shuffle 0 2 1
A gotil.ShuffleSeed 0 2 1
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 pseudo­random 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 pseudo­random 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