Ruby | Random base64() function Last Updated : 17 Dec, 2019 Comments Improve Suggest changes Like Article Like Report 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 # 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 # 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== Comment More infoAdvertise with us Next Article Ruby | Random ==() function M mayank5326 Follow Improve Article Tags : Ruby Ruby-Methods Ruby Random-class Similar Reads Ruby | Random urlsafe_base64() function 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 # Ruby code for Random.urlsafe_base64() method # loading library requ 1 min read Ruby | Random bytes() function Random#bytes() is a Random class method which returns random binary string containing size bytes. Syntax: Random.bytes() Parameter: Random values Return: random binary string containing size bytes. Example #1 : Ruby # Ruby code for Random.bytes() method # declaring Random value date_a = Random.new() 1 min read Ruby | Random ==() function Random#==() is a Random class method which checks whether the two random values are equal. Syntax: Random.==() Parameter: Random values Return: true - if random values are equal otherwise return false Example #1 : Ruby # Ruby code for Random.==() method # declaring Random value date_a = Random.new(1 1 min read Ruby | Random hex() function 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 # Ruby code for Random.hex() method # loading library require 'securerandom' # 1 min read Ruby | Random new() function Random#new() : new() is a Random class method which creates a new PRNG using seed to set the initial state. Syntax: Random.new() Parameter: Random values Return: a new PRNG using seed to set the initial state. Example #1 : Ruby # Ruby code for Random.new() method # declaring Random value date_a = Ra 1 min read Ruby | Random random_bytes() function Random#random_bytes() : random_bytes() is a Random class method which returns a random random_binary string. Syntax: Random.random_bytes() Parameter: Random values Return: a random random_binary string. Example #1 : Ruby # Ruby code for Random.random_bytes() method # loading library require 'securer 1 min read Like