Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "math/rand"
- "time"
- )
- // rollAllOnes returns the number of rounds it takes for a player
- // to roll all 1s when rolling 4 dice
- func rollAllOnes() (numberOfRolls int) {
- roundCounter := 0
- for {
- roundCounter++
- die1 := rand.Intn(6) + 1
- die2 := rand.Intn(6) + 1
- die3 := rand.Intn(6) + 1
- die4 := rand.Intn(6) + 1
- if die1 == 1 && die2 == 1 && die3 == 1 && die4 == 1 {
- numberOfRolls = roundCounter
- return
- }
- }
- }
- // main displays the result of rollAllOnes() into a comma delimited table of
- // NUM_ROWS rows and NUM_COLS columns
- func main() {
- rand.Seed(time.Now().UTC().UnixNano())
- NUM_ROWS := 20
- NUM_COLS := 25
- for i := 0; i < NUM_ROWS; i++ {
- for j := 0; j < NUM_COLS; j++ {
- numberOfRolls := rollAllOnes()
- fmt.Print(numberOfRolls, ",")
- }
- fmt.Println()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement