Tim
Tim

Reputation: 2592

Does generating two random numbers over just one affect the result?

I need to generate a random number between 1 and 52, for a card game (I know how to).

I could either use random (52) to directly reference each card in the pack, or I could do random(4) and random(13) to get the Suit and Value separately.

I can get the suit and value from the number between 1 and 52 with r div 13 and r mod 13 + 1.

But I am wondering if generating two random numbers will affect the "randomness" of the outcome. As the numbers generates will be pseudo random numbers, so that could affect it in some way?

And if the low numbers 4 and 13 vs 52 don't make a difference, is there a value where this could become an issue?

Upvotes: 1

Views: 40

Answers (1)

Sneftel
Sneftel

Reputation: 41474

If you're using a low-quality PRNG (like your average rand() implementation: Sure it'll affect stuff, but not in a way which is easily predictable without knowing your exact PRNG implementation and your exact code. Either one might be "better" than the other, for some value of "better".

If you're using a good-quality PRNG: Nah, doesn't matter. Go wild.

Upvotes: 3

Related Questions