Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Takes 3 optional params: an int code_length, a string "separator" and a look-up "table" (hash).
- def my_uuid_code(
- code_length = 24,
- separator: '-',
- table: { "0" => '0', "1" => '1', "2" => '2', "3" => '3', "4" => '4', "5" => '5',
- "6" => '6', "7" => '7', "8" => '8', "9" => '9',
- "A" => 'E', "B" => 'J', "C" => 'N', "D" => 'P', "E" => 'V', "F" => 'X' })
- posibilities = 16**code_length
- return rand(posibilities).to_s(16).upcase.rjust(code_length, '0').chars.map { |digit|
- table[digit] }.join.scan(/.{1,4}/).join(separator)
- end
Add Comment
Please, Sign In to add comment