Santosh
Santosh

Reputation: 33

Random Number generation

What should be the approach to generate 10 unique numbers that should not match among a group of 10 people's generated answer ?

Upvotes: 1

Views: 389

Answers (2)

cha0site
cha0site

Reputation: 10717

You could use OS facilities to generate a GUID (globally unique identifier).

A GUID is a 32-digit hexadecimal that looks like this: {21EC2020-3AEA-1069-A2DD-08002B30309D} (shamelessly stolen from the GUID wikipedia article). That makes it a 128 bit number. Now, it has all those annoying characters in the way, but there's nothing stopping you from removing the extraneous character and converting from hex and treating it as a plain number.

For practical reasons, you'll want to note that a 128-bit number is a bit unwieldy in some languages, such as C99. But you can still use compiler extensions (GCC has __uint128_t) or deal with it some other way.

Upvotes: 2

earthling42
earthling42

Reputation: 976

This one has a nice solution. I'm assuming you have to give numbers 1-10 to 10 different people in a random way (but the principle also works if you have 10 (or more) different, non-consecutive numbers).

Upvotes: 3

Related Questions