Randomising the chance that something will appear

BlitzMax Forums/BlitzMax Programming/Randomising the chance that something will appear

This is the way I do it:

Function picksomething(probabilities#[])
   p#=rnd(0,1)
   t#=0
   i=0
   while t<=p
      t:+probabilities[i]
      i:+1
   wend
   return i - 1 
End Function


Local probabilities#[5]
probabilities=[.1,.1,.1,.2,.5]

number=picksomething(probabilities