rand2.go 450 B

12345678910111213141516171819202122232425
  1. package main
  2. import (
  3. "crypto/rand"
  4. "fmt"
  5. "math/big"
  6. )
  7. // Outputs cryptographically secure pseudo random number between min and max
  8. // using crypt/rand.
  9. func randomNumber(min, max int64) int64 {
  10. num, e := rand.Int(rand.Reader, big.NewInt(int64(max)))
  11. if e != nil {
  12. fmt.Print(e)
  13. }
  14. return num.Int64() + min
  15. }
  16. func main() {
  17. // 10 dice rolls
  18. for i := 0; i < 10; i++ {
  19. fmt.Println(randomNumber(1, 6))
  20. }
  21. }