I need to generate a unique six digit alpha-numeric code. To save in my database as voucher no: for every transaction.
Answer
I used this
require 'sha1'
srand
seed = "--#{rand(10000)}--#{Time.now}--"
Digest::SHA1.hexdigest(seed)[0,6]
How to generate a random string in Ruby This link was useful
No comments:
Post a Comment