+ 3

How to make an array with random numbers?

27th Nov 2017, 9:14 AM
Bogdan
Bogdan - avatar
3 Answers
27th Nov 2017, 9:17 AM
Nithiwat
Nithiwat - avatar
+ 3
#include <random> #include <array> int main() { std::mt19937_64 engine; std::uniform_int_distribution<> distribution{0, 99}; std::array<int, 10> arr; for (auto &x : arr) x = distribution(engine); }
27th Nov 2017, 10:24 AM
Timon Paßlick
+ 1
fill each position of the array with a value returned from random function for loop{ array[i]= random() } just remember that you have to calibrate the result, meaning that random returns something between 0 and 1, so you need to multiply it by 10 and so on.
27th Nov 2017, 9:59 AM
Dmitrii
Dmitrii - avatar