I have created a simple random script that changes numbers every second.
local infLoopNum = 1 while infLoopNum == 1 do randomNum = math.random(1,100) print(randomNum) wait(1) end
I know its 6 lines, but I cant figure it out.
Ok, there are a couple of thing that can be improved here, for one the infLoopNum is not necessary, as a simple while true do loop works just fine. Second, it is highly encouraged to use a math.randomseed(tick()) before doing anything with math.random(), with all things said, the final result should look similar to:
math.randomseed(tick()) while true do randomNum = math.random(0,100) print(randomNum) wait(1) end
Although theking48989987's answer is valid, there is a faster, and better way to make random numbers in your game.
Using the userdata, Random, added in 2017, is much faster than using math.random(). This also encourages you to use Random seeds instead of optionally using seeds. Random is faster than math.random because it Random uses a different, faster algorithm(the difference is significant).
Take a look at the code below!
Code:
local RandomSeed = Random.new(tick()) -- Like math.randomseed(tick()) while true do -- Creates a Random integer between 0 and 100 local RandomNumber = RandomSeed:NextInteger(0,100) print(RandomNumber) wait(1) end
Hopefully this helped!