Thursday, 17 May 2018

alphanumeric - How to generate unique six digit alpha-numeric code in Ruby



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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...