github.com/binbinly/pkg@v0.0.11-0.20240321014439-f4fbf666eb0f/util/fastrand_test.go (about)

     1  package util
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestNewRand(t *testing.T) {
    10  	rd := NewRand(1)
    11  	assert.Equal(t, int64(5577006791947779410), rd.Int63())
    12  
    13  	rd = NewRand()
    14  	for i := 1; i < 1000; i++ {
    15  		assert.Equal(t, true, rd.Intn(i) < i)
    16  		assert.Equal(t, true, rd.Int63n(int64(i)) < int64(i))
    17  		assert.Equal(t, true, Rand.Intn(i) < i)
    18  		assert.Equal(t, true, Rand.Int63n(int64(i)) < int64(i))
    19  	}
    20  }