Randomising the chance that something will appear

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

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I suggest you create an array with 1 element for each object, and in that element store the floating point percentage `weight` for that item.

Then to look up an item, generate a floating point percentage:

Local Percentage:Float=FloatRnd()*NumberOfArrayElements


Then implement a binary search which starts at the middle of the array and reads the weight of that item and goes from there to find the closest matching weight. Your percentages in the array have to be sorted in order. That will be a lot quicker than searching through the array.