Ruby Random base64()函数
Random#base64() : base64() 是一个随机类方法,它返回一个随机的base64字符串。
语法。Random.base64()
参数。随机值
返回:一个随机的base64字符串。
例子 #1 :
# Ruby code for Random.base64() method
# loading library
require 'securerandom'
# declaring Random value
date_a = SecureRandom.base64
# declaring Random value
date_b = SecureRandom.base64(10)
# base64 value
puts "Random base64 form : #{date_a}\n\n"
puts "Random base64 form : #{date_b}\n\n"
输出:
Random base64 form : Xddr+KZ3CiXB53jy3wWlUg==
Random base64 form : l8K9nCZ/YvD4Pw==
例子 #2 :
# Ruby code for Random.base64() method
# loading library
require 'securerandom'
# declaring Random value
date_a = SecureRandom.base64(4)
# declaring Random value
date_b = SecureRandom.base64(34)
# base64 value
puts "Random base64 form : #{date_a}\n\n"
puts "Random base64 form : #{date_b}\n\n"
输出:
Random base64 form : nS+YAg==
Random base64 form : frVMwU+z3K9/lUmG82uHiBOtFH8fn0zDhwzibyhH7v+XCQ==