Actually.. I'd go as far as saying that the most of the how-do I questions seem to be related to math one way or another. Distances, speeds, enemy prediction, probabilities, Logic (or lack of), trigonometry, basic matrix math, 3d/isometric projections. Makes me wonder don't they teach math anymore?

— I need to think.. There was a time I knew things like this. it's been so many years I have forgotten..

Okay I will read through it. I have not had the time for it yet.

Edit:

Okay I read through the topic. I already had this solution in mind but my case is a little bit different so it whould not work for me (I think).

I safe my probabilities in an array and each of this probabilities can be ranging from 0%-100%. So if there are for example 5 different probabilities their sum can be greater or smaller than 100%.

I will show you an example. I attached a picture of the array. Each of this values can range from 0-100, representing % chances. 50% is the base value at the start of the game. The values are dynamic. Each Y row is an action the AI can make and each X row is the % chance of the object he is using for this action.

Let's say the first action (Y 0) is "destroy". And let's say the AI has 6 things he is able to destroy. X1=window, X2=door, X3=car, X4=house, X5=smartphone, X6=TV.

First i randomly choose an Y value to determine which action the AI is doing. After that I have to randomly let the AI pick an X value to determine with which object it is interacting. And this should be dependent on the % chances. If X1 is 0% the AI whould never destroy a window if he wants to destroy something. If X3 and X5 are both 100% than it whould always destroy either a car or a smartphone if the AI decides to destroy something.

So i have to set those values in relation to each other, but have to keep their own % chances. My had is about to explode.

I hope my problem is now clearer. There might be an easier solution than my approach but It gives me hadache.^^

step through each probability from high to low ( the high to low bit is important)

on each step I set the return value appropriately.

lets take your first example -

80% 60% and 30%

so you would step through these in high to low order

and lets say our percentage to check is 50%

so it would pass the first two (< 80 and < 60 ) but fail the third.

If you have 3 or 10 possibilities it makes no real difference (providing they are all different)

In your latest version you would need to take your (5 ?) possible % and pass them (hight to low) to a function that just does the above. This function would be probably be easier to write if you had a fixed number of possibilities (5,8,10, whatever) even if some of these possibilities were just padding.

Thank you Joannak for your afford. But I described my problem badly in the first post.

And RamPackWobble whank you, too. But what if the first probability is 100%? Than the others whould never occur.

I have to find another way around this. :/

Edit:

And what if I instead go from low to high? So it will pass all 0% chances (they whould anyways never occur). But if the last 2 are 100% there is the same problem.

I think I now have a solution:

roll=round(random(X1+X2+X3+X4+X5+X6...))

if roll <=X1 - case 1

if roll >X1 & roll <= X1+X2 - case 2 occurs

if roll >X1+X2 & roll <= X1+X2+X3 - case 3 occurs

if roll >X1+X2+X3 & roll <= X1+X2+X3+X4 - case 4 occurs

if roll X1+X2+X3+X4 & roll <= X1+X2+X3+X4+X5 - case 5 occurs

if roll X1+X2+X3+X4+X5 & roll <= X1+X2+X3+X4+X5+X6 - case 6 occurs

So this whould ensure, that the AI does check all probabilities, even if there are more at 0% or 100%. The other good thing about this whould be that there is always an X case choosen (except all cases have 0% chance).

The values itself are dynamic but the number of X cases are static. So I think I could use this. Whould this be correct on the maths side?

then first time 100 would set the return to be "1" but this would then be over written by the 90 setting the return to be "2" which would then be overwritten by the 80 setting the return to be "3" the 70 would not alter the return value nor would the 60 so the return ("3") would indicate it fell into the 80% range...

True - so you could also include a check for that and then pick one at random ? But, what is the chance of there being 2 or more with the same chance and would it matter if it picks the lower one in the list ?

This is the method I've used in the past and it worked for me - maybe you can take the idea and alter it to your needs or maybe you need another approach.

Yes it needs to be possible for each case to occur. Because in my example the AI whould never destroy the window if he wants to destroy something.. even though he has a 100% chance to want to destroy a window.

I'm currently setting up the 10,000 loop and I then will post the .capx.

Awesome! I figured it out. I had to swap "rolls/x0" to "x0/rolls". I will soon upload the .capx so everyone who will need this can look at it.^^

Edit 2:

Here is the .capx. On the top left you can see all rolls. On the left the static % chances given in the array. On the right side the dynamic case occurences.

Edit 3:

I updated the .capx so everyone, who needs this solution, can easily comprehend how it works.