Unique and random are somewhat orthagonal concepts.  In order to
enforce the uniqueness, you're placing a constraint on the random
values, so they're not really totally random.  For the random part,
#randRange(0, 999999)# will take care of it.  For the uniqueness,
you'll have to check the generated value against all others in the
database, and if the value is already in there, generate another
random value.  Repeat until you find one that is unique.

Keep in mind that your gamut is only a million values, which isn't
particularly large.  I don't know how many records you expect to
store, but if it's more than a couple thousand, I'd consider upping
the max value if randomness is at all important.

cheers,
barneyb

On Feb 11, 2008 1:39 PM, Les Irvin <[EMAIL PROTECTED]> wrote:
> Is there a slick way to do this in CF?  Let's say I have a set of
> records - one field of which is for a unique and random 6 digit
> number.  When adding a new record, what the best way to assign its
> random number that's not already assigned to another record?
>
> Thanks in advance,
> Les
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;160198600;22374440;w

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:298749
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to