I'm having troubles with classes. I have a class that generates random numbers, and I want to use this random number generator in another class to create a Powerball simulator.
This is my .cpp file for the random number generator:
#include "RandomNumber.h" #include <random> #include <utility> using namespace std; RandomNumber::RandomNumber( int min, int max, bool minInclusive, bool maxInclusive ) : mMinimum( min ), mMaximum( max ) { if (mMinimum > mMaximum) { swap( mMinimum, mMaximum ); } if (!minInclusive) { mMinimum++; } if (!maxInclusive) { mMaximum--; } } int RandomNumber::random( ) { static random_device rd; static mt19937 generator(rd()); uniform_int_distribution<> distro( mMinimum, mMaximum ); return( distro( generator ) ); } This is my header file for the random number generator:
#ifndef RandomNumber_h #define RandomNumber_h #include <stdio.h> class RandomNumber { public: RandomNumber( int min, int max, bool minInclusive = true, bool maxInclusive= true ); // supply a number between min and max inclusive int random( ); private: int mMinimum, mMaximum; }; #endif /* RandomNumbers_h */ I wanted to call the member function in another class called PowerballLottery and store the 6 values if they're within the appropriate range, I tried to use
RandomNumber.random( 1, 69 ) and
RandomNumber::random( 1, 69 ) but neither worked. I'm wondering what is the correct syntax. Thank you so much for reading this post.