Open In App

Ruby | Random hex() function

Improve
Improve
Like Article
Like
Save
Share
Report

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


Last Updated : 17 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads