-1

I was using this module for Perl, Crypt::PRNG, to generate random numbers. The number-generation seems truly random when using the random string command, it can use digits 0-9 as well as other characters and create a random string of the specified number of digits, the problem is the leading 0's.

perl -MCrypt::PRNG=:all -E "say random_string_from("1234567890", n)"

where n is the number of digits, is there a executable command similar to the one above to fix the leading 0's so I can for sure get an n digit number? My intent is to fix only the first digit to "123456789". Does anyone know how to do this? Thanks in advance.

J. Linne
  • 275
  • 4
  • 15

2 Answers2

0

How about

random_string_from("123456789", 1) . random_string_from("1234567890", $n-1)
redneb
  • 21,794
  • 6
  • 42
  • 54
0

Put the Crypt::PRNG code in a while loop until the leading character is not a 0.

zaph
  • 111,848
  • 21
  • 189
  • 228