gitee.com/zhongguo168a/gocodes@v0.0.0-20230609140523-e1828349603f/myx/randutil/rand_test.go (about)

     1  package randutil
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestWeight(t *testing.T) {
     9  	weight := map[int]int{
    10  		1: 9000,
    11  		2: 600,
    12  		3: 300,
    13  		4: 100,
    14  	}
    15  
    16  	count := map[int]int{}
    17  	for i := 0; i < 100000; i++ {
    18  		count[Weight(weight)]++
    19  	}
    20  
    21  	fmt.Println(count) // map[1:89738 2:6253 3:3004 4:1005]
    22  }