I want to generate a random number between specified range, but when i run the following code. it gives error , can any one explain the error please?
#include <iostream> #include <random> using namespace std; unsigned long int starting=2347483648; unsigned long int ending=3994967296; unsigned int rand(unsigned long int first,unsigned long int last) { std::random_device rd; std::mt19937 eng(rd()); std::uniform_int_distribution<> distr(first, last); return (unsigned int)distr(eng) << ' '; } int main() { cout<<rand(1,ending);//generate random number in this range } The program breaks and gives an error
invalid min and max arguments for uniform_int
Explain the reason of error and tell me how can i generate the random numbers between the above specified range
uniform_int_distributionis an int. And an unsigned long int cannot fit into an int.uniform_int_distribution.