红宝石 |随机 hex()函数
Random#hex() : hex()是一个 Random 类方法,它检查返回一个随机的十六进制字符串。
Syntax: Random.hex()
Parameter: Random values
Return: a random hexadecimal string.
示例 #1:hex() 方法示例
# Ruby code for Random.hex() method
# loading library
require 'securerandom'
# declaring Random value
date_a = SecureRandom.hex
# declaring Random value
date_b = SecureRandom.hex
# hex value
puts "Random hex form : #{date_a}\n\n"
puts "Random hex form : #{date_b}\n\n"
输出 :
Random hex form : e16fbb325cb2118ce32fe1c87287dcb4
Random hex form : 1b60f4bc7d3b6e1efa06f5b6e101009e
示例 #2:
# Ruby code for Random.hex() method
# loading library
require 'securerandom'
# declaring Random value
date_a = SecureRandom.hex
# declaring Random value
date_b = SecureRandom.hex
# hex value
puts "Random hex form : #{date_a}\n\n"
puts "Random hex form : #{date_b}\n\n"
输出 :
Random hex form : 6800f7ae74b3d9704a633dfa77f093bf
Random hex form : 79e04823672b5b1913691499f9d07f71