local randomOreSize = math.random(10,30)/10
--This will give a value between 1.0 and 3.0 (example: 1.5, 2.3, 2.9 etc)
How can i make it so the chance to pick a higher value is lower? Like the higher the randomOreSize value is the rarer it is to be picked? Like randomOreSize = (between 1 and 2) would be more common than randomOreSize = (between 2.5 and 3)
found a nice formula online: math.floor(math.abs(math.random() - math.random()) * (1 + max - min) + min)
this should give you a random integer between the range max and min with a higher probability of integers closer to min occurring.
another cool formula: 1 - math.sqrt(1 - math.random())
this also has the same effect as the previous one but it may be more/less weighted torwards giving values closer to 0
I know there is already a solution but I decided to mess with @centau_ri’s first formula a bit to come up with my own
local Table1 = {}
local Table2 = {}
function RandomScalling1(Min, Max, Decimals)
local RandomOreSize = math.abs(math.random() - math.random()) * (1 + Max - Min) + Min
return math.floor(RandomOreSize * 10^Decimals) / 10^Decimals
end
function RandomScalling2(Min, Max, Decimals)
local OreSizeTable = {}
for i = 1, math.floor(Max), 1 do
local RandomNumber = Random.new():NextNumber(Min, Max)
local RandomOreSize = math.floor(RandomNumber * 10^Decimals) / 10^Decimals
table.insert(OreSizeTable, RandomOreSize)
end
table.sort(OreSizeTable)
local RandomOreSize = math.abs(math.random() - math.random()) * (#OreSizeTable) + 1
return OreSizeTable[math.floor(RandomOreSize)]
end
for i = 1, 20, 1 do
table.insert(Table1, RandomScalling1(1, 100, 2))
table.insert(Table2, RandomScalling2(1, 100, 2))
end
table.sort(Table1)
table.sort(Table2)
print("other formula", Table1)
print("my formula", Table2)
the two prints at the end will print out two tables containing both methods done 20 times
the first table is the first formula centauri showed but with a bit of changes
the second table is the a method I came up with that utilizes that first formula
personally I think mine works a bit better, anyways I hope this helps you