pixelhandler

Pushin' & pullin' pixels on the net

Ruby Block to Create Random Token String Without Offending

In creating rant.cc as a short URL generator I wanted to avoid generating random text that would be offensive, so the block below attempts to avoid creating some text string you may have to apologize to your mother about.
Create random token with Ruby (random_token.rb) download
1
2
3
4
5
6
7
8
9
10
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

Comments