Ruby | Random rand() function Last Updated : 17 Dec, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Random#rand() : rand() is a Random class method which generates a random value. Syntax: Random.rand() Parameter: Random values Return: generates a random value. Example #1 : Ruby # Ruby code for Random.rand() method # declaring Random value date_a = Random.rand() # new arbitrary random value puts "Random form : #{date_a}\n\n" Output : Random form : 0.19492446216402715 Example #2 : Ruby # Ruby code for Random.rand() method # declaring Random value date_b = Random.rand() date_a = Random.rand(10) # new arbitrary random value puts "Random form : #{date_b}\n\n" puts "Random form : #{date_a}\n\n" Output : Random form : 0.175729980681539 Random form : 1 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 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 ==() 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 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 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 random_number() function Random#random_number() : random_number() is a Random class method which checks returns a random number from raw random bytes Syntax: Random.random_number() Parameter: Random values Return: random number from raw random bytes Example #1 : Ruby # Ruby code for Random.random_number() method # loading l 1 min read Ruby | Random new_seed() function Random#new_seed() : new_seed() is a Random class method which returns a random seed value. Syntax: Random.new_seed() Parameter: Random values Return: a random seed value Example #1 : Ruby # Ruby code for Random.new_seed() method # declaring Random value date_a = Random.new_seed() # new arbitrary ran 1 min read Like