So I've picked up C++ again after being away from it for 10+ years...*sigh* (the mistakes we make lol). I made a random number generator and work as intended.
My question is: Is there a more efficient way to write this? or perhaps a more "correct" way to implement this code? If not...then I'll move on.Code:#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { //time based randomizer srand(time(0)); //init counter int count = 1; //init minimum value int min = 1; //loop for generator for(int x=1; x<=25; x++){ //random number generator equation int num = min+(rand()%15000); //max number if(num>=9999){ num=9999; } //text counter cout << count; count++; cout << ". "; //print random number cout << num << endl; } }




Reply With Quote