Guest User

Untitled

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