Sagi Dayan
92e3c4ea7d
All checks were successful
ci / check for spelling errors (pull_request) Successful in 21s
ci / code quality (lint/tests) (pull_request) Successful in 2m29s
ci / Make sure build does not fail (pull_request) Successful in 2m25s
ci / notify-fail (pull_request) Has been skipped
ci / check for spelling errors (push) Successful in 22s
ci / code quality (lint/tests) (push) Successful in 1m53s
ci / Make sure build does not fail (push) Successful in 2m55s
ci / notify-fail (push) Has been skipped
Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
23 lines
362 B
Go
23 lines
362 B
Go
package common
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"math/big"
|
|
"reflect"
|
|
)
|
|
|
|
func ShuffleSlice(slice interface{}) {
|
|
rv := reflect.ValueOf(slice)
|
|
swap := reflect.Swapper(slice)
|
|
|
|
length := rv.Len()
|
|
|
|
for i := length - 1; i > 0; i-- {
|
|
j, err := rand.Int(rand.Reader, big.NewInt(int64(i+1)))
|
|
if err != nil {
|
|
panic("Shuffle error")
|
|
}
|
|
|
|
swap(i, int(j.Int64()))
|
|
}
|
|
}
|