如何在Ruby中生成唯一的六位字母数字代码

Ama*_*r S 5 ruby alphanumeric

我需要生成一个唯一的六位数字数字代码.要在我的数据库中保存为凭证号码:对于每笔交易.

Ama*_*r S 3

我用过这个

  require 'sha1'
  srand
  seed = "--#{rand(10000)}--#{Time.now}--"
  Digest::SHA1.hexdigest(seed)[0,6]
Run Code Online (Sandbox Code Playgroud)

如何在 Ruby 中生成随机字符串 这个链接很有用