I want to generate some random id values. I know there are many ways one can do this. But I want to understand why the code below is not working. It gives the same id most of the times; about 1/10 is different, but 9/10 it is the same. Where is the error, and how can I fix it? Thank you for the help.
require "random/isaac"
def rnd_alpha_numeric_id()
srcstr = "abcdefghjkmnpqrstuvwxyz" ## all except i, l and o
rndinst = Random::ISAAC.new
rndstr = srcstr.chars
.sample(6, rndinst)
.join
rndnum = rndinst.rand(100000..999999)
return "#{rndstr}-#{rndnum}"
end
10.times do |i|
puts "#{i}: #{rnd_alpha_numeric_id()}"
end
Link to Crystal playground: https://play.crystal-lang.org/#/r/7980