fork(1) download
  1. #include <iostream>
  2. #include <random>
  3.  
  4. int main()
  5. {
  6. // All letters (exchange the dots for the actual letters)
  7. static std::string const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  8.  
  9. // Initialize the random-number generation
  10. std::random_device rd;
  11. std::mt19937 gen(rd());
  12.  
  13. // This distribution will generate a value that will work as
  14. // an index into the `letters` string
  15. std::uniform_int_distribution<> dis(0, letters.size() - 1);
  16.  
  17. for (unsigned i = 0; i < 10; ++i)
  18. {
  19. // Generate one random character
  20. char random_character = letters[dis(gen)];
  21. std::cout << "Random character: '" << random_character << "'\n";
  22. }
  23. }
  24.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Random character: 'z'
Random character: 'o'
Random character: 'l'
Random character: 'Z'
Random character: 'H'
Random character: 'N'
Random character: 'b'
Random character: 'u'
Random character: 'W'
Random character: 'y'