Golang crypto/rand.Int() function example
package crypto/rand
Int returns a uniform random value in [0, max). *max is the given input (2nd parameter). The function will panic if max <= 0.
Golang crypto/rand.Int() function usage example
package main
import (
"crypto/rand"
"fmt"
"math/big"
)
func main() {
var n *big.Int
var err error
max := *big.NewInt(99999999999)
n, err = rand.Int(rand.Reader, &max)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%d\n", n)
}
Example output :
go run cryptorand.go
48752046463
Reference :
Advertisement
Something interesting
Tutorials
+6.9k Golang : Calculate BMI and risk category
+19.2k Golang : Check whether a network interface is up on your machine
+8.5k Golang : How to check variable or object type during runtime?
+19.2k Golang : Populate dropdown with html/template example
+16.3k Golang :Trim white spaces from a string
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+24.5k Golang : How to validate URL the right way
+11.2k Golang : Calculate Relative Strength Index(RSI) example
+15.4k Golang : invalid character ',' looking for beginning of value
+16.5k Golang : Execute terminal command to remote machine example
+9.5k Golang : Changing a RGBA image number of channels with OpenCV