0
$\begingroup$

I have very little idea about random numbers and patterns, so I am not sure whether this is actually possible or not.

I want to generate random numbers, that will follow a fixed pattern (perhaps this itself breaks the definition of 'randomness'?). Say for example, a number whose every alternate digit will be even/odd, like 123456. For such a pattern, say of 30 digits, I want to generate random numbers. And when generated, I want to verify the number against the pattern (so here I will verify whether the random number generated has every alternate digit as odd/even, if so, then it succeeds the check)

Is there any way to develop a fairly complicated (and if I may, notoriously difficult to find out by anybody else) pattern and generate random numbers in that pattern?

$\endgroup$

1 Answer 1

1
$\begingroup$

Yes, the problem is much more with defining a pattern you like than with the random numbers. Taking your alternate even/odd example, each digit has five choices, so you can just generate a random number from $0$ through $4$ for each digit. If the digit is supposed to be an even one, double it. If the digit is supposed to be odd, double it and add $1$. Now you have a number with digits alternating as desired that is randomly chosen among all the numbers that satisfy your criterion.

The problem you are seeing is that this is too easy a pattern for someone to identify. Choosing an appropriately hard pattern is not really a mathematical problem. You might just pick some ten digit prime number $p$ and have your pattern be multiples of that. When you want a random number thirty digits long, generate a random between $0$ and $10^{30}/p$, multiply by $p$ and report the result. Again your reported number will be random in the acceptable space. Clearly there are many patterns that can be defined.

$\endgroup$
8
  • $\begingroup$ Okay, so suppose the the prime number I pick is 5915587277. The pattern has to be a multiple of it, so suppose it is 12, so the pattern becomes 5915587277*12 = 70987047324. So I have to generate a random number between 0 and 10^30/70987047324. A simple random.randint() between 0 and 10^30/70987047324 gives, for example, 7250449821803687962. So how do I verify it now, that this is indeed a number following my pattern? $\endgroup$ Commented May 8, 2015 at 7:27
  • $\begingroup$ You didn't finish. Now you multiply $7250449821803687962 \cdot 70987047324=514688024620665764396223113688$ which is your number. You don't need to check because you constructed it correctly. If you do want to check, you do $514688024620665764396223113688 \pmod {70987047324}=0$ The mod operator is represented by the percent sign in many computer languages. You don't need the factor $12$ here if you want more numbers to be acceptable. $\endgroup$ Commented May 8, 2015 at 14:26
  • $\begingroup$ Yep, right. Thanks! $\endgroup$ Commented May 8, 2015 at 16:16
  • $\begingroup$ Hey sorry, I just looked at it again, how come it is random? We first get 7250449821803687962, which we then multiply with 70987047324, to get a result. Which will of course be divisible by 70987047324, since it is one of the multipliers. What is random in it? $\endgroup$ Commented Oct 30, 2015 at 17:22
  • $\begingroup$ "Random" can be used in many ways. It looked to me that you were using it as "numbers that do not have an obvious pattern to somebody who doesn't know how they are created". $111111111111$ and $123123123123$ would fail this test, even if they were in fact the output of a random number generator. The number I suggested (if you had lots in that class) would fail the tests of a computer random number, but it certainly "looks random". You originally asked for numbers that fit some pattern. Please clarify what you want. $\endgroup$ Commented Oct 30, 2015 at 23:26

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.