Skip to content

Instantly share code, notes, and snippets.

@smagch
Created May 16, 2015 07:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smagch/3dfa1583ff98fd11ffcb to your computer and use it in GitHub Desktop.
Save smagch/3dfa1583ff98fd11ffcb to your computer and use it in GitHub Desktop.
Golang: Random 6 Digit http://play.golang.org/p/tKvAnqvhrm
package main
import (
"crypto/rand"
"log"
"math/big"
)
func sixDigits() int64 {
max := big.NewInt(999999)
n, err := rand.Int(rand.Reader, max)
if err != nil {
log.Fatal(err)
}
return n.Int64()
}
func main() {
for i := 0; i < 100; i++ {
s := sixDigits()
log.Printf("%06d\n", s)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment