Declare an array of twenty-six characters. In a loop from zero to twenty-four (inclusive) generate a random value between '0'
and '9'
, and add to the array. Terminate the array with the string terminator. Now you have a string with 25 random decimal digits.
For the actual random-number generation, I suggest you look into the new C++11 random number functionality, especially std::uniform_int_distribution
.
Combine that with the std::generate
function from the standard algorithm library, and you can do it with just a couple of lines.
4
solved C++ generate 25 digit random number?