#ifndef _RANDOMWALK_H #define _RANDOMWALK_H // Owen Astrachan, 6/20/96, modified 5/1/99 // class for implementing a one dimensional random walk // // constructor specifies number of steps to take, random walk // goes left or right with equal probability // // two methods for running simulation: // // void Simulate() -- run a complete simulation // // Init(); HasMore(); Next() -- idiom for starting and iterating // one step at a time // accessor functions: // // int Position() -- returns x coordinate // (# steps left/right from origin) // int Current() -- alias for GetPosition() // // int TotalSteps() -- returns total # steps taken class RandomWalk { public: RandomWalk(int maxSteps); // constructor, parameter = max # steps void Init(); // take first step of walk bool HasMore(); // returns false if walk finished, else true void Next(); // take next step of random walk void Simulate(); // take all steps in simulation int Position() const; // returns position (x coord) of walker int Current() const; // same as position int TotalSteps() const; // returns total # of steps taken private: void TakeStep(); // simulate one step of walk int myPosition; // current x coordinate int mySteps; // # of steps taken int myMaxSteps; // maximum # of steps allowed }; #endif