How to generate some random addresses(string) in ruby?
DEUbQpgKyGDAjNqRXcpMYVD3HunVjCrH1G
DHcjoCTL2rHnAuKmWam64QfZv6H3DG3S6f
DSM1eJ6yXiaATHGXVmmznF1wuEuEzYvGHz
How to generate some random addresses(string) in ruby?
DEUbQpgKyGDAjNqRXcpMYVD3HunVjCrH1G
DHcjoCTL2rHnAuKmWam64QfZv6H3DG3S6f
DSM1eJ6yXiaATHGXVmmznF1wuEuEzYvGHz
If you want it to be unique, you can use SecureRandom. The simplest way would be using
SecureRandom.uuid
which generates ID like
irb(main):001:0> SecureRandom.uuid
=> "0d218853-5ef8-46df-85b1-e7e7af18c0ba"
If you want it guaranteed to be unique, you may want to add timestamp:
Digest::MD5.hexdigest "#{SecureRandom.hex(10)}-#{DateTime.now.to_s}"
which generates
irb(main):002:0> Digest::MD5.hexdigest "#{SecureRandom.hex(10)}-#{DateTime.now.to_s}"
=> "15aaf4a73969c67afccdfdaf629a310e"
such a thing?
Digest::MD5.hexdigest('foo') # => "acbd18db4cc2f85cedef654fccc4a4d8"
For random folder names i do
timestamp = Time.new.strftime("%Y-%m-%dT%H-%M-%S%z")
"#{timestamp}_#{("%04x" % rand(16**4))}"