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.
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.
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.
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
local numberString = tostring(math.random(1, 100)) .. ".";
while true do
numerString ..= tostring(math.random(0, 9))
--dont forget to stop eventually
end