Link to home
Start Free TrialLog in
Avatar of chrissp26
chrissp26

asked on

Random 6 digit code

Hello,

I need to generate 250,000 6 digit unique random codes.

The codes must contain any alphanumeric characters but it must contain at least one of each.

These need to be placed into an access db to send to a print company.

I know coldfusion has several random functions but how to put them into practice is another thing entirely plus, i'm not sure how to stop duplicates and make sure every code has at least 1 number and 1 letter.

Can someone either show me an example, or point me to a place?

Thanks in advance

Chris
Avatar of chrissp26
chrissp26

ASKER

Isn't there anyone here who can help?

Thanks

Chris
ASKER CERTIFIED SOLUTION
Avatar of aseusainc
aseusainc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Pure Genius!!!

Thanks ever so much for your help. I'm going to sit down for the next four years and study what you have done :)

Thanks for your help.

Chris
Pretty simple stuff really.

1st, we know that we MUST have 1 number and 1 letter.  So digit1 we pick from a list of numbers and start a list with the value, digit2 we pick from a list of letters then randomly insert it at either the front or the back of the list.  Then we just proceed through 3-6.  We randomly pick which list to choose from (letters or numbers), then randomly pick a value, then randomly put it in front of or behind the code list.  At the end, I'm just removing the commas from the list to make a string.

Theres no checking for dupes, but it would be a pretty slim chance of getting a dupe.  You can either code something in, which is going to add a TON of processing overhead, as you'll need to check each value against the database.  If you want to do this, let us know.

otherwise, just do a

SELECT DISTINCT thecode
FROM   tblCodes

and make sure the rowcount is 250000.  If you come up with less than 250000, you got a dupe.

Thanks for the points.  Good luck w/ your project!
Thanks for that, I used a little SQL to check for Dupes and double checked it with the DISTINCT query as well to make sure the number I got from the first added to the number I got from the second equalled the total ammount.

So it balanced.

Thanks again for your help I am extremly grateful

Chris