Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ generate a random number between 0 and 100,000

what is the best way to do this? my compiler shows RAND_MAX = 32,767. so I'm curious how I can get a uniform random generation of values between 0 and 100,000?

like image 204
Medic3000 Avatar asked Feb 14 '23 19:02

Medic3000


1 Answers

I'll just put juanchopanza's comment into answer.

Use the <random> header if your compiler provides it (C++11).

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, 10000);

std::cout << dis(gen) << std::endl;
like image 168
teh internets is made of catz Avatar answered Feb 28 '23 11:02

teh internets is made of catz