Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i make a randomiser have a range between 0-100?

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.

2 answers

✓ Accepted answer

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

##How to make Random numbers

Although theking48989987's answer is valid, there is a faster, and better way to make random numbers in your game.

##Random vs. math.random()

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).

##How to use Random numbers!

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.