### random number above 32767

i'm trying to figure out how to get and display a random number above the 32767 integer. could some one give me a good explanation or some example to get a better understand it. Im using the following code to get random numbers but only work with less than 5 digits. any help?
 ``12345678910111213141516171819202122232425`` `````` if (Maxdigit == 5)// maximum digit of the desire random # { mNumber = 100000; } for (int i=0; i= 10000) { cout << randomNumber << "\t"; } } if (Maxdigit == 6) { mNumber = 10000000; } for (int i=0; i= 10 * 100000) { cout << randomNumber << "\t"; } }``````
There are good examples here: http://www.cplusplus.com/reference/cstdlib/rand/

e.g. with Maxdigit == 5: `rand()%(100000-32767)+32767`
Use the C++11 random number library.

 ``123456789101112131415161718192021222324252627`` ``````#include #include #include int main() { const int max_digits = 12 ; // max digits in the random number generated // compute max value long long max_value = 1 ; for( int i = 0 ; i < max_digits ; ++i ) max_value *= 10 ; max_value -= 1 ; // random number generator seeded with time // http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine std::mt19937 rng( std::time(0) ) ; // pseudo random integers uniformly distributed in [ -max_value, max_value ] // http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution std::uniform_int_distribution distr( -max_value, max_value ) ; for( int i = 0 ; i < 20 ; ++i ) { const long long random_number = distr(rng) ; // generate a random number std::cout << random_number << '\n' ; } }``````

http://coliru.stacked-crooked.com/a/f94e980761140dbc
Alternatively, if the library isn't available, rand()|(rand()<<15)|((rand()&3)<<30). Make sure that RAND_MAX == (1 << 16) - 1 before using this, though.
thanks
Topic archived. No new replies allowed.