mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-27 15:27:06 -08:00
Fix random logic in Nim ports
This commit is contained in:
@@ -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"
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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 =
|
||||||
|
|||||||
Reference in New Issue
Block a user