Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

[Ruby] Random Str Gen

By: a guest on Feb 15th, 2013  |  syntax: Ruby  |  size: 0.36 KB  |  views: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #Random Str Generator...
  2. #Simple and effective by Mr. P-teo
  3. #Learning Beginner Ruby
  4.  
  5. random_range = ('a'..'z').to_a
  6.  
  7. print "String Length: "
  8. str_len = gets.to_i
  9. random_string = 'String: '
  10.  
  11. char = 0;
  12. while(char <= str_len)
  13.         rand_number = Random.rand(24)
  14.         random_string = random_string + random_range[rand_number].to_s
  15.         char += 1
  16. end
  17.  
  18. puts random_string
clone this paste RAW Paste Data