You not only want them to be unpredictable, but also unique.
Here's a technique: Randomly come up with two very large prime numbers. Call them p and q. q must be larger than p. Keep these numbers secret, because you'll be using them as your key generator from here on.
Each time you want to generate a new identifier:
- Let
n
= (number_of_rows) + 1;
- Let
id
= p^(n) MOD q
Most large number libraries have a powermod
method, so it would be
let n = (number_of_rows) + 1;
let id = powermod(l, n, m);
If, for my primes, I picked
p = 533000401
q = 553105243
Then
533000401^1 mod 553105243 = 533000401
533000401^2 mod 553105243 = 338207751
533000401^3 mod 553105243 = 288526476
533000401^4 mod 553105243 = 520004588
533000401^5 mod 553105243 = 485019742
533000401^6 mod 553105243 = 154299236
533000401^7 mod 553105243 = 345441135
533000401^8 mod 553105243 = 548307409
533000401^9 mod 553105243 = 352554000
533000401^10 mod 553105243 = 116366514
533000401^11 mod 553105243 = 262938285
533000401^12 mod 553105243 = 551979652
533000401^13 mod 553105243 = 81299520
533000401^14 mod 553105243 = 485628040
533000401^15 mod 553105243 = 129148293
533000401^16 mod 553105243 = 77088382
533000401^17 mod 553105243 = 377106983
533000401^18 mod 553105243 = 533584982
533000401^19 mod 553105243 = 362875056
533000401^20 mod 553105243 = 432282485
Even though it appears random, you're guaranteed to get no repetitions until you reach q
Of course, if someone figures out what your two initial prime numbers are, they would be able to guess the next number from the previous, so you would have to keep them secret. But I don't believe there's a way to work out what the source numbers are (short of just trying each possible pair of prime numbers, which of cause would take a prohibitively long time).
Here's a page on .NET fiddle to demonstrate this: https://dotnetfiddle.net/oUkbvy