Ruby | Random bytes() function
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 :
date_a = Random. new ()
date_b = Random. new ()
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 :
date_a = Random. new .bytes( 5 )
date_b = Random. new ()
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
Last Updated :
17 Dec, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...