feat(Go-Tool): ArrayList添加深度复制方法以及单测类、添加Rand随机获取参数方法、RandByWeight根据权重随机获取奖励方法

This commit is contained in:
huangzj
2020-06-30 11:47:38 +08:00
parent e43051db30
commit d1d47051d6
7 changed files with 334 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
/*
* @Author : huangzj
* @Time : 2020/6/29 17:16
* @Description
*/
package rand
import (
"Go-Tool/util/rand"
"fmt"
"strconv"
"testing"
)
func TestRandByWeight(t *testing.T) {
fmt.Printf(strconv.Itoa(rand.GetRandValueByWeight([]int{10, 20, 30, 50})))
list, list1 := rand.GetAwardByWeight([][]int{{2, 2, 10}, {3, 3, 4}})
for _, r := range list {
fmt.Println(strconv.Itoa(r))
}
for _, r := range list1 {
fmt.Println(strconv.Itoa(r))
}
fmt.Println(rand.GetByWeight([]int{10, 11, 12, 13}, []int{20, 30, 40, 50}))
list2, list3 := rand.GetAwardByWeightWithLeftAward([][]int{{2, 3, 30}, {3, 3, 40}})
for _, r := range list2 {
fmt.Println(strconv.Itoa(r))
}
for _, r := range list3 {
for _, r1 := range r {
fmt.Println(strconv.Itoa(r1))
}
}
list4 := rand.GetCountAwardsFromPool([][]int{{1, 2, 30}, {2, 2, 40}, {3, 2, 50}}, 2)
for _, r := range list4 {
for _, r1 := range r {
fmt.Println(strconv.Itoa(r1))
}
}
list5 := rand.GetAwardByPercentage([][]int{{20, 3, 99}, {90, 3, 10}, {12, 3, 22}}, 100)
for _, r := range list5 {
fmt.Println(strconv.Itoa(r))
}
}