Created
July 27, 2012 18:34
-
-
Save adhithyan15/3189648 to your computer and use it in GitHub Desktop.
A ruby method to generate a random number with given number of digits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_random_number_with_n_digits(input_n_digit) | |
smallest_number_of_nplus1_digits = 10**input_n_digit | |
smallest_number_of_n_digits = 10**(input_n_digit-1) | |
random_n_digit_number = Random.rand(smallest_number_of_nplus1_digits-smallest_number_of_n_digits)+smallest_number_of_n_digits | |
return random_n_digit_number | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment