Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adhithyan15/3189648 to your computer and use it in GitHub Desktop.
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
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