codewars / content-issues

Higher level issue tracker for the Codewars content.
15 stars 1 forks source link

Replace `rand` with `std::random_device` in C++ #33

Open Voileexperiments opened 3 years ago

Voileexperiments commented 3 years ago

I'm seeing a lot of C++ kata using C's rand, which should be replaced by std::random_device and the likes:

std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis_i(0, 10000);
std::uniform_real_distribution<> dis_d(0.0, 1.0);
int random_int = dis_i(gen);
double random_double = dis_d(gen);
hobovsky commented 3 years ago

It's also addressed in docs: https://deploy-preview-311--reverent-edison-2864ea.netlify.app/languages/cpp/authoring/index/#random-utilities and presented in example test suite: https://deploy-preview-311--reverent-edison-2864ea.netlify.app/languages/cpp/authoring/index/#example-test-suite

And then there's this exchange: https://github.com/codewars/docs/issues/208#issuecomment-829462827

Feel free to participate :)