Skip to content
Related Articles

Related Articles

Improve Article

Ruby | Random urlsafe_base64() function

  • Last Updated : 17 Dec, 2019
Geek Week

Random#urlsafe_base64() : urlsafe_base64() is a Random class method which returns a random URL-safe base64 string.

Syntax: Random.urlsafe_base64()

Parameter: Random values

Return: a random URL-safe base64 string.

Example #1 :






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

Output :

Random urlsafe_base64 form : nVLWr7IMELKxX6YnIy3oJw

Random urlsafe_base64 form : UQgpGRS2ozAM8Oq_2xABew

Example #2 :




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

Output :

Random urlsafe_base64 form : EsRwCaYJIXGOKQ

Random urlsafe_base64 form : _sXDkaMbC9KOhuYW

My Personal Notes arrow_drop_up
Recommended Articles
Page :