Lets say I wanted the user input to be randomized. Like if the user inputted "1234567890"
The output would be like "5684319027" Or any random number, as the numbers got randomized.
So how would I randomize a user input?
Lets say I wanted the user input to be randomized. Like if the user inputted "1234567890"
The output would be like "5684319027" Or any random number, as the numbers got randomized.
So how would I randomize a user input?
You can use std::shuffle
to randomize the order of elements of pretty much any ordered structure. You can use this on an std::string
, which would rearrange the individual characters. Here's an example of usage:
// at the top of your file
#include <algorithm>
// in your main code
std::string str; // define a string variable
std::cin >> str; // get user input into the string
// shuffle the string with a default random engine
std::shuffle(str.begin(), str.end(), std::default_random_engine(std::random_device{}()));
// use the now-shuffled string...