Rails 3: Generate unique codes (coupons)

后端 未结 6 1179
借酒劲吻你
借酒劲吻你 2021-01-30 18:29

What\'s the best way to generate unique codes to use as coupon codes?

Thanks.

6条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 19:16

    In Ruby's standard library there is SecureRandom for this:

    SecureRandom.hex(3)
    

    The length of the output is double of what the length input specified.

提交回复
热议问题