Tell me more ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

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?

share|improve this question
You're correct. The problem becomes trickier if you include 0 in your choice of digits and it is not allowed to lead. – Aron Ahmadia Aug 4 '12 at 10:25
1  
This questions seems to confuse the concept of number (which is independent from its representation) with the concept of numeral, i.e. the symbol or name that stands for it. Please specify what you really intend (e.g. a real positive number less than one whose decimal representation contains only a given set of digits) and the desired distribution. Sometimes for this sort of problems the hard part is the question, not the answer! – Stefano M Aug 4 '12 at 19:50

1 Answer

up vote 7 down vote accepted

Your proposal appears to make sense but what would be important to ask first is what probability distribution you want on those numbers. The set of numbers with only certain digits is rather peculiar as it is specific to the base-10 number system you choose. It would be interesting to hear what you intend to do with those random numbers!

share|improve this answer
Well, I would like to create "pseudo-random" divisions meant as an excercise for pupils to learn divide the pen-and-paper method. Certain digits "accumulated" to a number are easier to divide "by brain", than are others. The brain works like that. So divisors containing 1, 5, 0, 2 are easier to divide than those containing 7, 9, .. This is my use case. So I think it is not that much about the quality of adherece to the underlying distribution. – JohnDoe Aug 4 '12 at 20:23
1  
In that case, you indeed don't care about the distribution and your algorithm makes good sense. – Wolfgang Bangerth Aug 4 '12 at 20:27
Thank you for the explanation! – JohnDoe Aug 5 '12 at 20:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.