github.com/quic-go/quic-go@v0.44.0/internal/utils/rand_test.go (about) 1 package utils 2 3 import ( 4 . "github.com/onsi/ginkgo/v2" 5 . "github.com/onsi/gomega" 6 ) 7 8 var _ = Describe("Rand", func() { 9 It("generates random numbers", func() { 10 const ( 11 num = 1000 12 max = 12345678 13 ) 14 15 var values [num]int32 16 var r Rand 17 for i := 0; i < num; i++ { 18 v := r.Int31n(max) 19 Expect(v).To(And( 20 BeNumerically(">=", 0), 21 BeNumerically("<", max), 22 )) 23 values[i] = v 24 } 25 26 var sum uint64 27 for _, n := range values { 28 sum += uint64(n) 29 } 30 Expect(float64(sum) / num).To(BeNumerically("~", max/2, max/25)) 31 }) 32 })