rand_test.go 589 B

1234567891011121314151617181920212223242526272829303132333435
  1. package otherutils
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func TestRandChoiceByWeighted(t *testing.T) {
  7. items := [][]int64{
  8. {1, 1000},
  9. {2, 1000},
  10. {3, 500},
  11. {4, 10},
  12. }
  13. frequencies := make(map[int64]int64)
  14. for i := 0; i < 10000; i++ {
  15. selected, _ := RandChoiceByWeighted(items)
  16. //fmt.Println(selected)
  17. frequencies[selected]++
  18. }
  19. fmt.Println("Frequencies of selection after 10000 trials:")
  20. for k, v := range frequencies {
  21. fmt.Printf("%d: %d\n", k, v)
  22. }
  23. }
  24. func TestRandOneNum(t *testing.T) {
  25. for i := 0; i < 10; i++ {
  26. got, _ := RandInterval(0, 5)
  27. fmt.Println(got)
  28. }
  29. }