Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Ruby | Random base64() function

  • Last Updated : 17 Dec, 2019

Random#base64() : base64() is a Random class method which returns a random base64 string.

Syntax: Random.base64()

Parameter: Random values

Return: a random base64 string.

Example #1 :




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

Output :

Random base64 form : Xddr+KZ3CiXB53jy3wWlUg==

Random base64 form : l8K9nCZ/YvD4Pw==

Example #2 :




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

Output :

Random base64 form : nS+YAg==

Random base64 form : frVMwU+z3K9/lUmG82uHiBOtFH8fn0zDhwzibyhH7v+XCQ==

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!