0

There have been different questions about random number generation, but I have not seen one that would address the specific problem that I am trying to solve.

My requirements are:

  • I need to be able to generate a set of 5000 numbers, each number being 10 digits long
  • The numbers in this set must be random (or sufficiently random to not be easily guessed)
  • The numbers in this set must be unique
  • There is no need for order in the set elements
  • My software needs to be able to recognize that a number was generated using this algorithm. The members of a set are not stored (but a seed or some parameter used to construct them can be).
  • The process must be repeatable. Sets of 5000 numbers will be generated at different times. The same number CAN appear in different sets, but the algorithm to generate them must not be easily repeatable/recognizable. (For example, if I have a set of 5000 numbers, I should not be able to easily determine what will be the set of numbers in another set of 5000.)

Is there a way to do this? Any help or suggestions where to look would be appreciated. (This would be implemented in PHP, but I am just looking for an algorithm to do this.)

janman05
  • 57
  • 1
  • 7
  • Nothing so far, I'm in the process of figuring out what to do. I had some ideas but nothing that was happy with. – janman05 Oct 15 '14 at 13:59

2 Answers2

0

The simple way of doing what you're asking for is to have a procedure for taking a number and mapping it to something easily testable for. For instance you might decide to make the numbers be divisible by 1009. So just generate random numbers then round off to the nearest one divisible by 1009. Or you could generate 6 digit numbers then use a hashing algorithm to generate another 4 digits.

IF you know the rule, it is easy to verify that the number fits it. You will find few false positives. And it is a pattern that won't be easily found by chance.

But do keep in mind. "Won't be easily found by chance," is not the same as, "Will resist serious attempts to break it." If you need something secure, this is not how to go about it.

btilly
  • 43,296
  • 3
  • 59
  • 88
  • I can't have false positives, I absolutely need some guarantee that a number will appear once only in the set. (And yes, I'm not looking something totally unhackable.) – janman05 Oct 15 '14 at 13:32
0

Take an integer counter and encrypt it using a 10 digits to 10 digits encryption scheme.

The counter will run from 0 to 4999. To authenticate the number, just check after decryption that the high order digits are zeroes. (Chances that you form a valid code "by accident" are one over two million.)

To define several sets, you can let the counter run to higher values or use a different encryption key.

  • Hmm, not a bad idea. If the encryption key varies from set to set that will guarantee the values will not repeat. I will give it a try, and see if it works. Any suggestions for the encryption scheme to use? – janman05 Oct 15 '14 at 14:12
  • I am not a specialist. Have a look at http://stackoverflow.com/questions/959916/way-to-encrypt-a-single-int –  Oct 15 '14 at 14:36