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
+7k Golang : Decode XML data from RSS feed
+4.8k Linux : sudo yum updates not working
+88.7k Golang : How to convert character to ASCII and back
+24.6k Golang : Change file read or write permission example
+11k Golang : Command line file upload program to server example
+5.2k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+14.1k Golang : concatenate(combine) strings
+9.3k Golang : does not implement flag.Value (missing Set method)
+7.7k Gogland : Single File versus Go Application Run Configurations
+6k Golang : Denco multiplexer example
+10.4k Golang : Detect number of faces or vehicles in a photo
+7.8k Golang : How to execute code at certain day, hour and minute?