Skip to content
Related Articles

Related Articles

Ruby | Random uuid() function
  • Last Updated : 17 Dec, 2019

Random#uuid() : uuid() is a Random class method which checks returns a random v4 UUID (Universally Unique IDentifier).

Syntax: Random.uuid()

Parameter: Random values

Return: a random v4 UUID (Universally Unique IDentifier).

Example #1 :






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

Output :

Random uuid form : 219474f0-60c5-43b4-8e7f-f91b5c5e1f38

Random uuid form : d6800817-c27b-4651-8d98-dc12eec46706

Example #2 :




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

Output :

Random uuid form : f74b43f6-8b9c-4cd1-aff2-177f517b77aa

Random uuid form : baba4612-6931-46a0-aa8b-7a105fd2f194

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :