Thread: Key Generation
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Rech Jim Rech is offline
external usenet poster
 
Posts: 2,718
Default Key Generation

Start with:

Randomize Timer

rather than

Randomize Rnd()

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

--
Jim
"Sri" wrote in message
...
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 a

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.
--
Regards

Sri