Fix random logic in Nim ports

This commit is contained in:
Michael Adams
2023-08-05 01:49:11 -07:00
parent 76d65ddcb2
commit 3f25036fdc
5 changed files with 11 additions and 2 deletions

View File

@@ -4,6 +4,8 @@ var
bet, cardA, cardB, cardC, stash: int bet, cardA, cardB, cardC, stash: int
retry: bool = true retry: bool = true
randomize() # Seed the random number generator
proc printGreeting() = proc printGreeting() =
echo spaces(26),"ACEY DUCEY CARD GAME" echo spaces(26),"ACEY DUCEY CARD GAME"
echo spaces(15),"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" echo spaces(15),"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"

View File

@@ -10,6 +10,8 @@ var
prompt: string prompt: string
stillplaying: bool = true stillplaying: bool = true
randomize() # Seed the random number generator
# Seed 3 unique random numbers; indicate if they're all unique # Seed 3 unique random numbers; indicate if they're all unique
proc genSeed(): bool = proc genSeed(): bool =
for i in 1..3: for i in 1..3:

View File

@@ -4,6 +4,8 @@ var
wager, winnings, rollResult: int wager, winnings, rollResult: int
stillplaying: bool = true stillplaying: bool = true
randomize() # Seed the random number generator
proc tryAgain(): bool = proc tryAgain(): bool =
echo "WANT TO PLAY AGAIN? (YES OR NO)" echo "WANT TO PLAY AGAIN? (YES OR NO)"
var answer = readLine(stdin).normalize() var answer = readLine(stdin).normalize()

View File

@@ -6,6 +6,8 @@ var
z: string z: string
retry: bool = true retry: bool = true
randomize() # Seed the random number generator
echo spaces(34), "DICE" echo spaces(34), "DICE"
echo spaces(15), "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY" echo spaces(15), "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
echo "\n" echo "\n"

View File

@@ -4,10 +4,11 @@ var
carSpeed, diff, err, guess, trainSpeed, carTime: int carSpeed, diff, err, guess, trainSpeed, carTime: int
stillplaying: bool = true stillplaying: bool = true
randomize() # Seed the random number generator
# Return a tuple that'll be carSpeed, diff, trainSpeed # Return a tuple that'll be carSpeed, diff, trainSpeed
proc randomNumbers(): (int,int,int) = proc randomNumbers(): (int,int,int) =
randomize() result = (rand(41..65), rand(6..20), rand(21..39))
result = (rand(1..25)+40 , rand(1..15)+5 , rand(1..19)+20)
# Do we want to play again? # Do we want to play again?
proc tryAgain(): bool = proc tryAgain(): bool =