Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Ruby | Random bytes() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Random#bytes() is a Random class method which returns random binary string containing size bytes.

Syntax: Random.bytes()

Parameter: Random values

Return: random binary string containing size bytes.

Example #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"

Output :

Random bytes form : ??

Random bytes form : f??????

Example #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"

Output :

Random bytes form : ?}???

Random bytes form : TI     ???g&n
My Personal Notes arrow_drop_up
Last Updated : 17 Dec, 2019
Like Article
Save Article
Similar Reads