• 💀 Happy Halloween! 💀 It's time to vote for the best terrain! Check out the entries to Hive's HD Terrain Contest #2 - Vampire Folklore.❗️Poll closes on November 14, 2023. 🔗Click here to cast your vote!
  • 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 HD Level Design Contest #1 is OPEN! Contestants must create a maze with at least one entry point, and at least one exit point. The map should be made in HD mode, and should not be openable in SD. Only custom models from Hive's HD model and texture sections are allowed. The only exceptions are DNC models and omnilights. This is mainly a visual and design oriented contest, not technical. The UI and video walkthrough rules are there to give everyone an equal shot at victory by standardizing how viewers see the terrain. 🔗Click here to enter!

Completing a chance system with relative probabilites

Status
Not open for further replies.
Level 8
Joined
Mar 12, 2008
Messages
437
Yo. I want to spawn items regularly, and there are different classes of items, each class having a relative probability. Within each class, there's also a number of items, each with its relative probability within.

Each class is characterised by an integer, with the rel.prob. stored in an integer array. Within each class, the items are handled the same way. I have no problem with converting relative probabilities into absolute probabilities - you just divide each prob with the sum of all probs.

However, I don't really know how to take the final step, i.e. to actually pick a random item given the probability for each item.

How can I complete the system? Maybe it's not a good way to programme the system to begin with?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Create a real between 0 and the chances of all items together.
Then loop through the list of items and lower that created real by the chance of the picked item.
as soon as that real becomes equal to or less than 0, the picked item is the one that has to spawn
 
Status
Not open for further replies.
Top