Skip to content

Commit b89f95d

Browse files
committed
Simplify SecureRandom.base36
We can now assume `alphanumeric` exists.
1 parent 042e392 commit b89f95d

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

activesupport/lib/active_support/core_ext/securerandom.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module SecureRandom
1717
# p SecureRandom.base58 # => "4kUgL2pdQMSCQtjE"
1818
# p SecureRandom.base58(24) # => "77TMHrHJFvFDwodq8w7Ev2m7"
1919
def self.base58(n = 16)
20-
SecureRandom.alphanumeric(n, chars: BASE58_ALPHABET)
20+
alphanumeric(n, chars: BASE58_ALPHABET)
2121
end
2222

2323
# SecureRandom.base36 generates a random base36 string in lowercase.
@@ -32,10 +32,6 @@ def self.base58(n = 16)
3232
# p SecureRandom.base36 # => "4kugl2pdqmscqtje"
3333
# p SecureRandom.base36(24) # => "77tmhrhjfvfdwodq8w7ev2m7"
3434
def self.base36(n = 16)
35-
SecureRandom.random_bytes(n).unpack("C*").map do |byte|
36-
idx = byte % 64
37-
idx = SecureRandom.random_number(36) if idx >= 36
38-
BASE36_ALPHABET[idx]
39-
end.join
35+
alphanumeric(n, chars: BASE36_ALPHABET)
4036
end
4137
end

0 commit comments

Comments
 (0)