dice-roller/Coin/Coin.go

33 lines
716 B
Go

package Coin
import (
"fmt"
"math/rand"
"strings"
"gitlab.com/EternalWanderer/dice-roller/Colors"
)
func Toss(castAmount int) {
var (
coins []string
coin string
coinState int
)
for i := 0; i < castAmount; i++ {
coinState = rand.Intn(2)
if coinState == 0 {
coin = Colors.ColorYellow + "heads" + Colors.ColorReset
} else {
coin = Colors.ColorBlue + "tails" + Colors.ColorReset
}
coins = append(coins, coin)
}
if castAmount > 1 {
fmt.Printf("%sTossing %d coins...%s\n", Colors.ColorYellow, castAmount, Colors.ColorReset)
} else {
fmt.Printf("%sTossing coin...%s\n", Colors.ColorYellow, Colors.ColorReset)
}
fmt.Printf("\t%s\n", strings.Trim(fmt.Sprint(coins), "[]"))
}