I done this function:
Now! in your case you can use it like this:
It gives just a number between 0 to 4 but you can put it in array where you got the items.
Or in function:
Here is the code. I made it on GDscript, you can, but it can alter other language, also check for logic errors:
for i in range(arrayy.size()):
#Randomies be pressed down
#first start from zero
if 0<=random_num and random_num<=arrayy:
return 0+ transformm
for i in range(arrayy.size()-1):
#they must pluss together
#if array[i]<=random_num and random_num<array[i+1]:
if summatut<random_num and random_num<=summatut+arrayy[i+1]:
return i+1+ transformm
It works like this: on_normal_case([50,50],0) This gives 0 or 1, it has same probability both.
on_normal_case([50,50],1) This gives 1 or 2, it has same probability both.
on_normal_case([20,80],1) This gives 1 or 2, it has bigger change to get two.
on_normal_case([20,80,20,20,30],1) This give random numbers range 1-5 and bigger numbers are more likely than smaller numbers.
on_normal_case([20,80,0,0,20,20,30,0,0,0,0,33],45) This throw dices between numbers 45,46,49,50,51,56 you see when there is zero it never occure.
So it function returns just one random number that depends lenght of that arrayy array and transformm number, and ints in the array are probability weights that a number might occure, where that number is location on the array, pluss transformm number.