Ruby Block to Create Random Token String Without Offending

Billy Heaton 1 min read

def random_token
characters = 'BCDFGHJKLMNPQRSTVWXYZbcdfghjkmnpqrstvwxyz23456789-_'
temp_token = ''
srand
TOKEN_LENGTH.times do
pos = rand(characters.length)
temp_token += characters[pos..pos]
end
temp_token
end

About the Author

Billy Heaton
Billy Heaton

Software engineer with two decades of experience who favors Ruby and JavaScript to build web applications