Advertisement
Guest User

[Ruby] Random Str Gen

a guest
Feb 15th, 2013
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.36 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement