Advertisement
Guest User

Untitled

a guest
May 6th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <random>
  4. #include <chrono>
  5.  
  6. using namespace std;
  7.  
  8. string melangeLettre(string mot);
  9. int main()
  10. {
  11. cout << "Saisissez un mot mystere: n> ";
  12. string motMystere{};
  13. cin >> motMystere;
  14.  
  15. cout << "Quel est ce mot ?n";
  16. string const newMot{melangeLettre(motMystere)};
  17. cout << newMot << endl;
  18.  
  19. return {0};
  20. }
  21.  
  22. string melangeLettre(string mot)
  23. {
  24. size_t random = chrono::system_clock::now().time_since_epoch().count();
  25. mt19937 gen{random};
  26. string newMot{};
  27.  
  28. for (unsigned int i{}; i < mot.size(); ++i)
  29. {
  30. uniform_int_distribution<> getNbr(0, mot.size());
  31. int const alea{mot[getNbr(gen)]};
  32.  
  33. newMot.push_back(alea);
  34. mot.erase(alea, 1);
  35. }
  36.  
  37. return newMot;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement