Hi Guys,
someone knows how can i write a function that gives me a random number back between 1 and 3
PS: i am not allowed to use the liberaries .h
thx
There's other better random number generators but this one is the usual one for exercises:
http://www.cplusplus.com/reference/cstdlib/rand/?kw=rand
which library do i need for this ?
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
int main()
{
int randNum;
srand(time(NULL));
randNum = rand() % 2 + 1;
// %( modulus) 2 + 1 tells the program that
system("PAUSE");
return 0 ;
}
Last edited on