1234567891011121314151617181920212223242526272829 |
- package main
- import (
- "crypto/rand"
- "fmt"
- "math/big"
- "strings"
- "strconv"
- )
- // 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() {
- var sb strings.Builder
- for i := 0; i < 5; i++ {
- sb.WriteString( strconv.FormatInt(randomNumber(1, 6), 10) )
- }
- // Show a Diceware random number
- fmt.Println(sb.String())
- }
|