Skip to content

Commit

Permalink
fix train.ua random bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Fig-Con committed Oct 10, 2023
1 parent 2aa6776 commit 7b0554f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions 91_Train/lua/train.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ math.randomseed(os.time())
local ERROR_MARGIN <const> = 5.0

function play()
local car_speed = math.random(40, 65) --Between 40 and 64
local delta_time = math.random(5, 20) --Between 5 and 19
local train_speed = math.random(20, 39) --Between 20 and 38
local car_speed = 25*math.random() + 40--Between 40 and 64
local delta_time = 15*math.random() + 5--Between 5 and 19
local train_speed = 19*math.random() + 20--Between 20 and 38

print( string.format("\nA CAR TRAVELING AT %u MPH CAN MAKE A CERTAIN TRIP IN %u HOURS LESS THAN A TRAIN TRAVELING AT %u MPH.", car_speed, delta_time, train_speed) )

Expand Down

1 comment on commit 7b0554f

@RFigCon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made code similar to the BASIC code style, and fixed the boundary issues.

math.random() returns x, where 0<=x<1
math.random(0,1) returns x, where 0<=x<=1

Lua Docs

Please sign in to comment.