Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.84 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math/rand"
  6.     "time"
  7. )
  8.  
  9. // rollAllOnes returns the number of rounds it takes for a player
  10. // to roll all 1s when rolling 4 dice
  11. func rollAllOnes() (numberOfRolls int) {
  12.     roundCounter := 0
  13.     for {
  14.         roundCounter++
  15.         die1 := rand.Intn(6) + 1
  16.         die2 := rand.Intn(6) + 1
  17.         die3 := rand.Intn(6) + 1
  18.         die4 := rand.Intn(6) + 1
  19.         if die1 == 1 && die2 == 1 && die3 == 1 && die4 == 1 {
  20.             numberOfRolls = roundCounter
  21.             return
  22.         }
  23.     }
  24. }
  25.  
  26. // main displays the result of rollAllOnes() into a comma delimited table of
  27. // NUM_ROWS rows and NUM_COLS columns
  28. func main() {
  29.     rand.Seed(time.Now().UTC().UnixNano())
  30.     NUM_ROWS := 20
  31.     NUM_COLS := 25
  32.     for i := 0; i < NUM_ROWS; i++ {
  33.         for j := 0; j < NUM_COLS; j++ {
  34.             numberOfRolls := rollAllOnes()
  35.             fmt.Print(numberOfRolls, ",")
  36.         }
  37.         fmt.Println()
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement