I'm using a PRNG (PHP's default rand()
implementation) to generate unique 16 digit numbers. Does it make sense to generate digits one by one, or the number at once?
I'm using PHP.
I'm using a PRNG (PHP's default rand()
implementation) to generate unique 16 digit numbers. Does it make sense to generate digits one by one, or the number at once?
I'm using PHP.
In principle each arithmetic pseudo-random number generator (such as PHP's) has a finite period after which the same sequence of numbers will repeat. And most generators will generate a fixed minimum number of bits (often 32) for you internally at each step, no matter how large or small the range of results is that you asked for.
So generating each digit separately will eat up the sequence of your generator more quickly and thus make the resulting sequence of complete numbers less 'random' overall.
In practice the most relevant difference is probably that generating each digit separately is a lot more work.
Both of these effects, however, point in the same direction: You should generate your whole random number at once.
With a PRNG that has equal probability for "single decimal digits" as well as "16-digit decimal numbers", no, they should be equal.
However, the PRNG is unlikely to have perfect probability for base-10 numbers, so "possibly". It would depend on how much this influences the probabiity for any specific digit.
Bear in mind that a 16-digit number is up to 54 bits, so this may influence your decision as to if you should generate you number in pieces or not.