Skip to content

Commit

Permalink
Merge pull request #4 from mcampbell/use-array-sample-vs-homegrown
Browse files Browse the repository at this point in the history
Use builtin Array#sample vs "manual" random indexing
  • Loading branch information
stulzer authored May 11, 2024
2 parents 23eba56 + fbfa452 commit cd7b965
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/cuid2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.create(length)
entropy = ''

while entropy.length < length
random_prime = PRIMES[(rand * PRIMES.size).floor]
random_prime = PRIMES.sample
entropy += (rand * random_prime).floor.to_s(36)
end

Expand Down Expand Up @@ -42,7 +42,7 @@ def self.create(input, length = BIG_LENGTH)

class << self
def call(length = DEFAULT_LENGTH)
random_letter = ('a'..'z').to_a[(rand * 26).floor]
random_letter = ('a'..'z').to_a.sample
hash_input = (time + Entropy.create(length) + count + fingerprint).to_s

"#{random_letter}#{Cuid2::Hash.create(hash_input, length)[2..length]}"
Expand Down

0 comments on commit cd7b965

Please sign in to comment.