Hello, i'm roughly new to c# and i was wondering how to Have my program make a decision based on a percentage.

For example there's a 56% chance that a sprite on a map will move left and a 54% chance it will move right. Then there's another sprite that has a 48% chance to move left and a 52% percent chance it will move right, and there are many more sprites that each have different values. This inst very hard but once you have many different chances it gets really complicated

Is there any way to figure out were it will move without having to do making time consuming functions that convert the percentages to ratios then make many random functions and a bunch of if-statements to see weather it will move right or left.

Thanks.

Recommended Answers

All 2 Replies

If every sprite has its own probability method, I see no problem.
Or does the movement of a sprite depends on the movement of the others?

Is there any way to figure out were it will move without having to do making time consuming functions that convert the percentages to ratios then make many random functions and a bunch of if-statements to see weather it will move right or left.

Sure, but it has nothing to do with programming. Given enough time, the pixels with a higher chance of moving left will be all the way to the left, and the ones with a higher chance of moving right will be all the way to the right.

Now if you wanted to run a Monty-Carlo simulation of this, it doesn't take "a bunch of if-statements", you'll only need one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.