I feel a little amateurish dishing this one up - but I really dig this
little technique. Somehow it satisfies my skepticism of Unique Key
Generators -- and it keeps things numeric.
Matthew
http://www.builder.com/Programming/ScriptMagic/ss01g.html
ColdFusion Tips
Generate Unique Random Numbers
By Rob Bilson and Mike Van Hoozer
(6/30/98)
ColdFusion's RAND, RANDRANGE, and RANDOMIZE functions can be used to
generate random numbers, but none of them
addresses the need for generating unique random numbers. Unique random
numbers have many uses, especially in user
authentication and identification. One of the easiest ways to create a
unique random number in ColdFusion is to combine the
RAND function with a time and date stamp.
Using the time and date stamp ensures that even if the same random
numbers are generated--and you have a better chance of
winning the lottery than of seeing that happen--the time and date stamp
will be different:
<!--- Assign the current date and time to a variable. --->
<CFSET tdstamp="#DateFormat(Now(),'mmddyyyy')
##TimeFormat(Now(),'hhmmss')#">
<!--- Create a random number. --->
<CFSET randomnum1=RAND()*100000000>
<!--- Create another random number. --->
<CFSET randomnum2=RAND()*100000000>
<!--- Concatenate the first random number, the time and date stamp, and
the second random number. --->
<CFSET uniquenumber="#randomnum1##tdstamp
##randomnum2#">
<!--- Output the unique random number. --->
<CFOUTPUT>
Unique Random Number: #UniqueNumber#
</CFOUTPUT>
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists