Original Post
Hi, I've developed a handy STL-style container for storing and retrieving items randomly. Items can have different probabilities, and can either be removed from the set like cards from a deck, or come up again like rolling dice. hat.h hat container source code, revision 1.59 The C++ hat random container online documentation hat.DevPak package for those using dev-cpp. Installs hat.h in [dev-cpp]/include, and a bunch of example programs in [dev-cpp]/Examples/Hat. Some example uses (updated):
- loaded_die.cpp example of random sampling with replacement of unequally weighted objects
- advanced_dice.cpp roll a set of three dice using only one call to the random number generator
- cards.cpp cards are drawn from a deck, returned to the deck, and drawn again.
- multiple_distributions.cpp Use several different distributions to access a given set of items.
- custom_generator.cpp Example of specifying a user-designed custom random number generator.
- near_max.cpp Usually draw maximum valued item, but with some diminishing probability for further down the list.
- monster_drops.cpp get a couple random treasures from a master list, depending on monster level and type.
- fuzzy_logic.cpp It's 68 degrees fahrenheight in here; is it hot, fine, or cold?
- game_theory.cpp NPC makes a choice using a mixed strategy, so that it won't be predictable.
- bernoulli_process.cpp Simulate five trucks leave a warehouse, each with a 40% independent chance of being late.
- random_actions.cpp Choose a course of action based on preference and availability.
- stochastic_approximation.cpp AI learns to predict an unknown behavior pattern, with overall improving results, and scores it's performance.