Sep 24, 2013 at 1:56pm UTC
Why are you spamming the forum with the same question in multiple threads?
You already received some answers to this in www.cplusplus.com/forum/general/111465/
Sep 24, 2013 at 2:12pm UTC
coz no one answering my question..
okay,
how to delete topic?
Last edited on Sep 24, 2013 at 2:13pm UTC
Sep 24, 2013 at 2:24pm UTC
Take the word coming from the file and put it in a std::string. You then will call random shuffle to shuffle the word at random.
For example
1 2
std::string name("Brandon" );
std::random_shuffle(name.begin(), name.end());
Now you can also pass a generator to the function like so to make a bit more random.
1 2 3 4 5 6 7 8 9 10 11
int main()
{
std::srand(std::time(0));
std::string name("Brandon" );
std::random_shuffle(name.begin(), name.end(), [] (int i) {return std::rand() % i;});
std::cout << name;
return 0;
}
Now there is also the new std::shuffle() which came with C++11 that you can use also which is just like random shuffle except it works with a generator from the random header.
Last edited on Sep 24, 2013 at 2:25pm UTC