Guest User

Untitled

a guest
Apr 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #ifndef RANDOM_CHARACTER_H
  2. #define RANDOM_CHARACTER_H
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. char getRandomCharacter(char ch1, char ch2)
  7. {
  8. return static_cast<char>(ch1 + rand() % (ch2 - ch1 + 1));
  9. }
  10.  
  11. char getRandomLowerCaseLetter()
  12. {
  13. return getRandomCharacter('a', 'z');
  14. }
  15.  
  16. char getRandomUpperCaseLetter()
  17. {
  18. return getRandomCharacter('A', 'Z');
  19. }
  20.  
  21. char getRandomDigitCharacter()
  22. {
  23. return getRandomCharacter('0', '9');
  24. }
  25.  
  26. char getRandomCharacter()
  27. {
  28. return getRandomCharacter(0, 127);
  29. }
  30. #endif
Add Comment
Please, Sign In to add comment