Key Generation

S

Sri

Hi,

I am developing a "Project Tracker tool" using Excel VBA, where in people
will input their project details. Whenever a new project is submitted, I have
to generate a unique Key for them (like a auto generated password), which
will be used in future to make any modifications, thereby securing it safely.

So, I have tried using Randomise and Rnd to generate some random numbers
within a range and convert them in to some Alpha characters, which is working
fine.
But the only issue is it keeps generating the same set of keys all the time
and not unique sequences...

I'vel attached here the coding piece which i am using currently.....

""""
To produce random integers in a given range, use this formula:

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

--------- This is taken from Excel help section....

""""

My code...........

Randomize Rnd()

s = Chr(Int((90 - 65 + 1) * Rnd + 65))
s = s & Chr(Int((122 - 97 + 1) * Rnd + 97))
s = s & Chr(Int((57 - 48 + 1) * Rnd + 48))
s = s & Chr(Int((57 - 48 + 1) * Rnd + 48))
s = s & Chr(Int((122 - 97 + 1) * Rnd + 97))
s = s & Chr(Int((90 - 65 + 1) * Rnd + 65))

The below ones are the numbers repeatedly generated for almost 50 projects,
sometimes in a chain, the same numbers repeats...

Dc31hK
Fc23rH
Gw18jP
Ow15xW

My queries are:

1. Is the above piece of code correct? or can it be modified to generate a
unique sequence everytime.
2. Is there any other best way to do the same?

Thanks for your help.
 
J

Jim Rech

Start with:

Randomize Timer

rather than

Randomize Rnd()

which produces the same seed with every restart of Excel..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top