github.com/geph-official/geph2@v0.22.6-0.20210211030601-f527cb59b0df/libs/erand/erand.go (about)

     1  package erand
     2  
     3  import (
     4  	"crypto/rand"
     5  	"math/big"
     6  )
     7  
     8  // Int returns a cryptographically secure random number between 0 and max.
     9  func Int(max int) int {
    10  	b, err := rand.Int(rand.Reader, big.NewInt(int64(max)))
    11  	if err != nil {
    12  		panic(err)
    13  	}
    14  	return int(b.Int64())
    15  }