Random number generation with crypto/rand in Go
Random number is useful in many applications. From salting password to enabling secure transactions.
In this tutorial, we will learn how to generate random number in Go with crypto/rand library.
File : crypto-rand.go
package main
import "encoding/binary"
import "crypto/rand"
func main() {
var n int32
binary.Read(rand.Reader, binary.LittleEndian, &n)
println(n)
}
Run the code: > go run crytpo-rand.go
and see how it goes. :-)
Reference:
See also : Generate Random number with math/rand in Go
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+7.2k Golang : How to check if input string is a word?
+9.6k Golang : Create Temporary File
+9.6k Golang : Command line file upload program to server example
+15.4k Golang : How to generate QR codes?
+25k Golang : Encrypt and decrypt data with AES crypto
+5.7k Golang : Reverse by word
+3.9k Javascript : How to get width and height of a div?
+6.7k Golang : Error reading timestamp with GORM or SQL driver
+10.5k Golang : Detect user location with HTML5 geo-location
+12.3k Golang : Query string with space symbol %20 in between