B Seven
B Seven

Reputation: 45943

What is a good way to generate UUIDs of a given length that contain only numbers and letters in Ruby?

SecureRandom#urlsafe_base64 contains punctuation characters.

What is a good way to use it to generate a UUID of given length(12) containing only numbers, uppercase and lowercase letters?

Ruby 1.9.3

Upvotes: 1

Views: 150

Answers (1)

pguardiario
pguardiario

Reputation: 54984

How about:

SecureRandom.urlsafe_base64.gsub(/\W/, '')[0..11]
#=> "x7lADtl95FUH"

Upvotes: 3

Related Questions