12

We are generating random numbers 16 digits in length. One option that was put forward was to generate four random numbers of 4 digits each and concatenate them instead of just generating a single 16 digit random number. The reason accompanying the suggestion was that it would be harder to predict the next number in case there was an issue with the random number generator.

So is the concatenated random number better than a single random number?

13
  • 9
    Depending on how your pseudorandom number generator is implemented you might get the same number with both methods.
    – Philipp
    Commented May 23, 2016 at 16:27
  • 1
    @nwildner I'm curious, how could it make the RNG even weaker? I understand that the randomness could not increase, but I fail to see how it could decrease.
    – A. Darwin
    Commented May 23, 2016 at 17:12
  • 1
    @nwildner could you explain the "will increase entropy and security" further?
    – topher
    Commented May 23, 2016 at 18:01
  • 3
    @nwildner your math is wrong: 10^n + 10^n + 10^n + 10^n = 4(10^n). Also all 3 answers in that question state that the author's claim is incorrect.
    – topher
    Commented May 23, 2016 at 18:30
  • 4
    This video analyzes how the random number generator in Super Mario 64 works. It's not the most serious video, but at one point, the video's creator makes an interesting observation: The particular RNG used produces about 65000 different random numbers, but consistently produces them in the same order. As a result, when n numbers are selected consecutively, there aren't 65000^n possible results - there are only 65000 possible results, regardless of n! Whether or not your RNG will have the same problem depends on your implementation.
    – Kevin
    Commented May 23, 2016 at 23:28

3 Answers 3

25

So is the concatenated random number better than a single random number?

If the random generator really produces random data then it will not matter.

... it would be harder to predict the next number in case there was an issue with the random number generator.

If the issue is that the random generator is not that random at all then it might even be better for an attacker to get as much last outputs as possible because then the behavior could be better to predict. Of course this assumption depends highly on the internals of the random generator, so no general answer is possible.

But in general: if you need really good random data you should use a proper random generator. Your method will not improve the quality of the output if the random generator is bad, i.e it stays predictable. If you actually don't need true random data but only want to make sure that you get somewhat random data without a bias you should be careful because depending on how exactly you do it your method might add a bias to the output.

5
  • I don't understand how it's not more secure. The attacker wouldn't know you're putting several concatenated numbers together right? They would only see the result. Commented Jul 6, 2016 at 15:51
  • @TankorSmash: there is no difference between the attacker having to guess a number with 16 digits or 4 numbers with each 4 digits. The number of possible combinations is exactly the same. Commented Jul 6, 2016 at 16:02
  • But you said it would affect it, " it might even be better for an attacker to get as much last outputs as possible ". I understand that it's the same number, but the attacker would only see one output number, not realizing it was actually 4, so I don't see how it could hurt it. I guess it's hard to say for sure one way or the other without an example. Commented Jul 6, 2016 at 16:15
  • @TankorSmash: if the random generator is really bad you might get more information about its internal state when having 4 consecutive random numbers compared to having only a single number. And this information could then be used to predict future behavior. But, all of this really depends on the specifics of the random generator used. Commented Jul 6, 2016 at 17:42
  • I agree if they knew it was 4 random numbers, but they wouldn't at this point, they'd only see 16 digits and know nothing else. If they knew that, they'd know how the RNG worked you'd think. Commented Jul 6, 2016 at 17:44
1

This presentation about the concept of an unpredictable pseudo stream can help to clarify the ideas: https://class.coursera.org/crypto-preview/lecture/5 presentation in PDF http://spark-university.s3.amazonaws.com/stanford-crypto/slides/02.2-stream-annotated.pdf

An pseudorandom steam is unpredicatable, when no attacker can guess correctly the next content of the stream knowning the previous content, with probability larger than the random choice (1/2^(number of bits)) and reasonsable time.

Therefore, if you use any secure pseudorandom stream, such as Chacha20 (the pseudorandom stream is the stream used in this cipher to XOR the data), then by definition, the bytes are unpredictable. Otherwise, it would be a significant security breach in these stream ciphers.

-1

Typically combining consecutive results from the same pseudorandom number generator is inferior to using a single result. Think of it this way: the random number generator generates a certain number of results before cycling back to the first number it provided. If you use up four results at a time, there are only one quarter as many results that you can get - assuming that the possible number of results is a multiple of four, which is likely on a binary machine - so a brute force attack would only take one quarter as long to break your data.

In addition, the behavior of the data itself may be problematic when you combine consecutive results. For example, many random number generators provide individual numbers which have good statistical distributions, but this doesn't necessarily apply to combinations of consecutive numbers, where the random number generator may be more or less likely to generate runs of similar results than would a truly random source. For example, I once used a random number generator to simulate rolls of a six sided die, and when I summed three consecutive results, the behavior of consecutive results was such that I never got a sum of 18, over many thousand attempts.

I discuss consecutive results, but these arguments apply to use of nonconsecutive results as well when they are selected in a systematic way. Your best bet is just to select a better random number generator and use the results one at a time. The only time when you need to combine multiple results is when a single result doesn't have enough bits to satisfy your needs - rare with off the shelf pseudorandom number generators.

3
  • But how would an attacker know that it isn't just a random 16 digit number?
    – user64742
    Commented May 24, 2016 at 2:44
  • 1
    @TheGreatDuck: Kerckhoffs' principle, aka Shannon's maxim: "The enemy knows the system". Assuming the attacker is unlikely to guess true random numbers (used as a seed to the pseudorandom number generator) seems safe. Assuming the attacker doesn't know how the system works is wishful thinking.
    – David Cary
    Commented May 24, 2016 at 13:25
  • that may be true, but isn't generating a 16 digit number the same as generating 16 digits and appending them? Perhaps I don't understand the process.
    – user64742
    Commented May 24, 2016 at 14:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .