How would I pick a random number under 1

Hi, I am trying to make an egg opening system. For this egg-opening system there will be pets with chances under 1% for the player to hatch.

The issue is that random number generator I am using doesn’t go under 1%

The generator I am using to get a pet by chance:

	local max = 100
	local data = {}
	local chosen = math.random(0, max)
	
	for itemName, itemTable in pairs(rarities) do
		
		max = max - itemTable["Chance"]
		
		if chosen > max then
			table.insert(data,1,itemName)
			table.insert(data,2,itemTable["Chance"])
			table.insert(data,3,itemTable["Rarity"])
			return data
		end
	end

If you had to, you could have it go between 0 and 1,000 and then divide the result by 10 to get a value between 0 and 100, while still allowing it to have decimal places.

If you wanted something with 0.01 rarity, increase it to 10,000 and divide by 100.

4 Likes

Sorry, I am having trouble understanding. Can you please explain it through script?

Here’s the code I used for testing in studio real fast.

a = math.random(0,1000); print(a,a / 10);

--Output
-- 727 72.7
-- 157 15.7

If you wanted 2 decimal places, you could do 10,000 / 10

a = math.random(0,10000); print(a,a / 100);

--Output
-- 7327 73.27
-- 1570 15.70
2 Likes