Random Numbers

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
closed account (48T7M4Gy)
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
1
2
std::random_device randomizer;
int random_nr=randomizer()%4;
which library do i need for this ?
#include<random>
#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
Topic archived. No new replies allowed.