12345678910111213141516171819202122232425 |
- package main
- import (
- "crypto/rand"
- "fmt"
- "math/big"
- )
- // Outputs cryptographically secure pseudo random number between min and max
- // using crypt/rand.
- func randomNumber(min, max int64) int64 {
- num, e := rand.Int(rand.Reader, big.NewInt(int64(max)))
- if e != nil {
- fmt.Print(e)
- }
- return num.Int64() + min
- }
- func main() {
- // 10 dice rolls
- for i := 0; i < 10; i++ {
- fmt.Println(randomNumber(1, 6))
- }
- }
|