Ruby,如何產生隨機亂數?!

Ruby,如何產生隨機亂數?!

Method 1:
require 'securerandom'  #Ruby 2.0 included!
random_string = SecureRandom.hex

# outputs: 5b5cd0da3121fc53b4bc84d0c8af2e81
SecureRandom also has methods for:
  • base64
  • hex
  • random_bytes
  • random_number
Method 2:
require 'securerandom'
s = SecureRandom.urlsafe_base64(20)

留言

熱門文章