#include <iostream>
#include <ctime>
using std::cout;
int randRange (int low, int high)
{
return rand() % (high - low) + low;
}
int main()
{
srand(time(NULL));
cout << randRange(1, 21);
}
That's how I do it. IMO it's a bit cleaner. If anyone wants to comment and tell me how I can improve, please go ahead. I'm farely new and all criticism is helpful!