I am making randomly generated terrain that is made of 7x7x7 blocks. Each of them has percentage that defines its chance to spawn(max chance is 1000 and min is 1). The problem is that this is not working properly, for example: when something has 999 of chance and other this has 1 chance and then run the script there still be many second blocks. The code for picking a block to generate looks like it:
function Precentage() while true do Place = math.random(1,#Minerals) Blocks = Minerals[Place] if Blocks.prc.Value >= Gen then original = Minerals[Place] break else Gen = math.random(1,1000) Place = math.random(1,#Minerals) end end end
The 'prc value' is the percentage of the block.
I just run the script and I saw a field that has as many blocks which have 26 percentage as the block which have 999 percentage.
The problem here is you're not in control with the percentage of times the math.random function will pick a certain number. It might pick the number 42, 100 times, even though you have a wide minimum and maximum set - you and I didn't program that function, so how can we trust it, as far as percentages go?
What you might consider doing is creating a function that counts how many times a number is picked, in the range of 1,1000, and run it in a loop of maybe 10,0000 times, and then have it display the results - that may give you a better idea on how the random number generator is performing.
Once you know which numbers or number ranges come up, you can add IF.... THEN conditions to determine which items to spawn.
So apparently I changed some stuff and it fixed the problem
function Precentage() while true do Randomizer.Randomizer() Gen = math.random(1,1000) Place = math.random(1,#Minerals) Blocks = Minerals[Place] if Blocks.prc.Value >= Gen then original = Minerals[Place] break else end end end