使用隨機函數(shù)
- "math/rand"
package main
import (
"math/rand"
"time"
"fmt"
)
func main() {
v1 := shuffle_48()
fmt.Println(v1)
}
//定義長度
const CardListLen48 = 48
//除去大怪,小怪男公,紅桃2艾岂,*花2,方片2潭兽,黑桃A
var cardListAll = []int32{
0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, // ??
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, // ??
26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, //??
39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, // ??
}
//權(quán)重
func shuffle_48() []int32 {
cl := make([]int32,CardListLen48)
cl = cardListAll
for i := range cl {
s := rand.New(rand.NewSource(time.Now().UnixNano()))
j := s.Intn(CardListLen48) //0 ~ 隨機最長數(shù)值,還有直接返回int32 ...
cl[i], cl[j] = cl[j], cl[i] //交換位置
}
return cl
}