Skip to content
Related Articles

Related Articles

Ruby | Random random_number() function

Improve Article
Save Article
Like Article
  • Last Updated : 17 Dec, 2019

Random#random_number() : random_number() is a Random class method which checks returns a random number from raw random bytes

Syntax: Random.random_number()

Parameter: Random values

Return: random number from raw random bytes

Example #1 :




# Ruby code for Random.random_number() method
  
# loading library
require 'securerandom'
  
# declaring Random value
date_a = SecureRandom.random_number
  
# declaring Random value
date_b = SecureRandom.random_number
  
# random_number value
puts "Random random_number form : #{date_a}\n\n"
  
puts "Random random_number form : #{date_b}\n\n"

Output :

Random random_number form : 0.06094009368827358

Random random_number form : 0.23398922898567265

Example #2 :




# Ruby code for Random.random_number() method
  
# loading library
require 'securerandom'
  
# declaring Random value
date_a = SecureRandom.random_number(10)
  
# declaring Random value
date_b = SecureRandom.random_number(200)
  
# random_number value
puts "Random random_number form : #{date_a}\n\n"
  
puts "Random random_number form : #{date_b}\n\n"

Output :

Random random_number form : 6

Random random_number form : 82

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!