class OmwRandomString
Public Class Methods
generate(length = 16)
click to toggle source
# File lib/omw_random_string.rb, line 2 def self.generate(length = 16) # allowed_chars contains the characters to be used by the generator allowed_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" # Contains the new random string random_string = "" # set seed for random number to time srand Time.now.to_i # lookup char given the random number as position of the char # add new char to random_string var # This is exectude 'length' times for i in 1..length do random_string += allowed_chars[rand(allowed_chars.length)] end # return the random_string so it can be used in your code return random_string end