Skip to main content
edited tags
Link
Christian Clason
  • 12.4k
  • 3
  • 49
  • 68
Tweeted twitter.com/#!/StackSciComp/status/231972322062503936
Source Link
JohnDoe
  • 201
  • 1
  • 7

How to assure that a number only contains a certain range of digits?

Say I would like to generate a pseudo-random number, which only contains the digits 1, 4, 7 (this is arbitrary).

My first guess would be to create and array "147" and create random numbers in the range [0..2] and use these numbers as an index into this array to concatenate a number in a loop.

I wonder if there is a more "mathematics"-like answer?