hey guys,
my question is quick and simple. how do i generate random numbers but between 1 and 52?
i know how to generate numer between 0 and 52 but no idea how to do it if it starting with 1. thanks a lot :)
#include <iostream>
using std::cout;
using std::endl;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
int main(){
int randomNumber;
//randomize random number generator using current time
srand(time(0));
cout<<"Generate random numbers between 1-52"<<'\n'<<endl;
for(int counter=1;counter<=10;counter++){
randomNumber=1+rand()%52;
cout<<randomNumber<<' ';
if(counter==5){
cout<<endl;
}//end if
}//end for
cout<<endl;
//type your favorite pause statement HERE e.j "cin.ignore();" or whatever you want
return 0; //indicate successful termination
}//end main
/*
*
* from C++ How to program,5th edition book:
*
* randomNumber=shiftingValue + rand() % scalingFactor;
*
* where shiftingValue is equal to the first number in the desired range of consecutive integers and scalingFactor is equal to the width of the desired range of consecutive int egers. The exercises show that it is possible to choose integers at random from sets of values other than ranges of consecutive integers.
*/