红宝石 |随机字节()函数
Random#bytes()是一个 Random 类方法,它返回包含大小字节的随机二进制字符串。
Syntax: Random.bytes()
Parameter: Random values
Return: random binary string containing size bytes.
示例 #1:
# Ruby code for Random.bytes() method
# declaring Random value
date_a = Random.new()
# declaring Random value
date_b = Random.new()
# bytes value
puts "Random bytes form : #{date_a.bytes(2)}\n\n"
puts "Random bytes form : #{date_b.bytes(10)}\n\n"
输出 :
Random bytes form : ??
Random bytes form : f??????
示例 #2:
# Ruby code for Random.bytes() method
# declaring Random value
date_a = Random.new.bytes(5)
# declaring Random value
date_b = Random.new()
# bytes value
puts "Random bytes form : #{date_a}\n\n"
puts "Random bytes form : #{date_b.bytes(10)}\n\n"
输出 :
Random bytes form : ?}???
Random bytes form : TI ???g&n