📜  红宝石 |随机字节()函数

📅  最后修改于: 2022-05-13 01:54:44.144000             🧑  作者: Mango

红宝石 |随机字节()函数

Random#bytes()是一个 Random 类方法,它返回包含大小字节的随机二进制字符串。

示例 #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