红宝石 |随机 base64()函数
Random#base64() : base64()是一个 Random 类方法,它返回一个随机的 base64字符串。
Syntax: Random.base64()
Parameter: Random values
Return: a random base64 string.
示例 #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==