Here's a basic framework for you. Add any number of weapons you like. Make sure you add some code somehwere to do srand()...I assume you already know that part. You could also incorporate some of what Salem said so that certain weapons are more likely than others to come up.
Code:# include <vector> # include <iostream> using namespace std; class weapon { public: weapon() {} virtual ~weapon() {} // other virtual functions here virtual void use_it() = 0; }; class shotgun : public weapon { public: // implement virtual functions here void use_it() { cout << "Firing shotgun!" << endl; } }; class grenade : public weapon { public: // implement virtual functions here void use_it() { cout << "Throwing grenade" << endl; } }; // Factory functions to create your objects weapon* create_shotgun() { return static_cast<weapon *>(new shotgun()); } weapon* create_grenade() { return static_cast<weapon *>(new grenade()); } // serves out weapons on a random basis class WeaponProvider { public: WeaponProvider() { // TODO: Add srand() code here } // register any number of weapons void register_weapon(weapon*(*create_function)()) { options_.push_back(create_function); } // get a random weapon, don't forget to delete it when you're done weapon* get_weapon() { int n = rand() % options_.size(); return options_[n](); } private: vector<weapon*(*)()> options_; }; // demo it int main() { WeaponProvider wp; wp.register_weapon(create_shotgun); wp.register_weapon(create_grenade); for (int i = 0; i < 10; i++) { weapon* w = wp.get_weapon(); w->use_it(); delete w; } }