Moved rng back to where needed and rewrote some thing to make it actually work it this time

This commit is contained in:
Nox Sluijtman 2022-08-20 13:37:07 +02:00
parent 2d560c42a0
commit 1e57a27bcf
2 changed files with 34 additions and 11 deletions

View file

@ -4,15 +4,26 @@ import (
"fmt"
"math/rand"
"strings"
"time"
"gitlab.com/EternalWanderer/dice-roller/Colors"
)
var (
surfaces, diceThrows, modidier int
initRandom bool
)
func InitRandom(initialised bool) {
if initialised {
return
}
rand.Seed(time.Now().Unix())
initRandom = true
}
func Cast(surfaces, diceThrows, modifier int) {
InitRandom(initRandom)
var (
casts []int
cast, total int
@ -46,13 +57,16 @@ func Cast(surfaces, diceThrows, modifier int) {
}
func SimpleCast() int {
InitRandom(initRandom)
var cast = rand.Intn(20) + 1
return cast
}
func Advantage(x, y int) (int, int, int) {
func Advantage() (int, int, int) {
x := SimpleCast()
y := SimpleCast()
if x > y {
return x, x, y
} else {
@ -60,7 +74,9 @@ func Advantage(x, y int) (int, int, int) {
}
}
func Disadvantage(x, y int) (int, int, int) {
func Disadvantage() (int, int, int) {
x := SimpleCast()
y := SimpleCast()
if x < y {
return x, x, y
} else {