Generating unique N-valued key

Posted by Bar on Stack Overflow See other posts from Stack Overflow or by Bar
Published on 2010-03-26T22:50:26Z Indexed on 2010/03/26 22:53 UTC
Read the original article Hit count: 311

Filed under:
|

Hi, StackOverflow!

I want to generate unique random, N-valued key. This key can contain numbers and latin characters, i.e. A-Za-z0-9.

The only solution I am thinking about is something like this (pseudocode):

key = "";
smb = "ABC…abc…0123456789"; // allowed symbols
for (i = 0; i < N; i++) {
    key += smb[rnd(0, smb.length() - 1)]; // select symbol at random position
}

Is there any better solution? What can you suggest?

TIA, Michael.

© Stack Overflow or respective owner

Related posts about random

Related posts about key