# How to make a RNG Generator like RNG World Cup

You can write your topic however you want, but you need to answer these questions:
I want to make an RNG like RNG World Cup. I can’t figure out how they do it. I have tried searching the developer hub, but have found no solutions.
Here is the game
RNG World Cup
It basically generates a random number with a decimal point. It is also not a
`math.random(1000, 9999)`
and then just divide it by 100 or something.

You can play the game to understand more.

1 Like

math.random() gives you between 0.0 and 1.0, you can scale that to any range by multiplying and adding.

1 Like

How could I make the random number infinite?

Like it has infinite possibilities for example. 1.92958190357138571239512790 or a number like that and it could keep going if you get lucky since if you do

``````math.random(1, 9999999999999999999999999999)
``````

or something like that it could always be one greater.

I have thought of making a script for example it grabs a random number 0 - 10 if it is 0 then it continues if it is greater than 0 then it will stop for example if it lands on 0 it will generate another number like 0.9 and if it lands on 0 again it will do 0.09, but if it doesn’t land on 0 it will stop and return the last number which was 0.09.

1 Like

You cant do this directly, you must use a trick, for this reason:

Numbers in lua can be integers, which I believe are always signed 32 bit, or 32 bit floating points numbers. I dont recall exactly how it decides which to use. A 32 bit integer can be up to about 2 billion, a float can be up to about 3.4 x 10^38, however, the space between two possible numbers gets bigger as you get further from zero. See this video for a more detailed explanation:

Since math.random() generates a float between 0 and 1, this means it only about half the range of a float.

You can do some tricks to get a bigger number with more possibilities. You can randomly choose an exponent (power of 10), and then keep generating a completely aribtrary number of decimal digits to multiply it by. You can get an almost unlimited number of possibilities that way, you just have to decide when to stop at that point. You cannot stretch it to cover all numbers between zero and infinity though, since that range is uncountably infinite.

This would also work for the same reasons.

Couldn’t you turn the number into a string?

You can, that would be similar to having an “arbitrary precision” number, like Python has.

Do you know how I could do that?

Yes, just keep generating digits and adding them to the end of a string, making sure the decimal place goes after the first non-zero digit. I don’t know what the statistical distribution would be like in this case, if that matters.

``````local numberString = "0.";
while true do
numerString ..= tostring(math.random(0, 9))

--dont forget to stop eventually
end
``````

How would I keep generating digits? and the first digits before the decimal are 1 through 100 how would I do that?

generate the first 3 digits seperately:

``````local numberString = tostring(math.random(1, 100)) .. ".";
while true do
numerString ..= tostring(math.random(0, 9))

--dont forget to stop eventually
end
``````

Couldn’t you do
`math.random(0, math.huge)`

This would give you half the range of a float, I think they want arbitrarily more precision.

`Random.new():NextNumber()`
Kinda obvious what to do with it next.

Number that I got from 1000 rolls

Thanks for the clarification, never actually tried that before