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.

2 comments
Not the solution, but a tip - you should Initialize your Gen variable at least once, BEFORE your While loop.
I have: "local Gen = 2" at the beginning of the whole script as well as all other values similarly. This is just part of selection of a block which makes the problem