Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Random hex() function

  • Last Updated : 17 Dec, 2019

Random#hex() : hex() is a Random class method which checks returns a random hexadecimal string.

Syntax: Random.hex()

Parameter: Random values

Return: a random hexadecimal string.

Example #1 : Example for hex() method




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

Output :

Random hex form : e16fbb325cb2118ce32fe1c87287dcb4

Random hex form : 1b60f4bc7d3b6e1efa06f5b6e101009e

Example #2 :




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

Output :

Random hex form : 6800f7ae74b3d9704a633dfa77f093bf

Random hex form : 79e04823672b5b1913691499f9d07f71

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!