Two issues there, really, it seems, Brian.

1) When you need more truly random numbers, you should call the Randomize 
function first, and in it you can provide both a seed and an alternative 
randomization algorithm. See the CF docs, such as (for cf9, which sadly comes 
up first in google search results):

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-6d3e.html


You could also consider using the createuuid function, which creates a 
different form of random number (with numbers and letters), which may have 
value. 

2) But you refer to getting the identity as a second step and using that. Are 
you saying THAT ends up being the same? If so, that would not be due to 
randomization issues, but rather a race condition.

You don’t say how you’re selecting the identity from the insert, but there are 
multiple ways, some better than others at reducing the likelihood of getting 
one from another insert. I’ll hold off on details until you clarify what you’re 
doing and whether this would be helpful. (Or perhaps someone else will chime in 
anyway.)

/charlie

From: cfaussie@googlegroups.com [mailto:cfaussie@googlegroups.com] On Behalf Of 
Brian Knott
Sent: Tuesday, January 26, 2016 5:31 PM
To: cfaussie@googlegroups.com
Subject: [cfaussie] SQL identity issue

 

Hi everyone.

 

I have an issue with inserting orders into a database.  What I currently do is 
create a random number and insert that number into the database when an order 
is inserted.  I then query the database to get the order number (unique ID 
generated by SQL Server).  Using this order number I then insert the items into 
an item table. 

 

The issue is that its possible for 2 orders to end up with the same unique 
number, this is because the random function is not actually that random.  If 
two people are submitting orders at the same time, they get the same random 
number.  This means that all of the items ordered go to one customer, and the 
other customer gets no items. 

 

Current code for the random number is

 

<cfset session.order.uniquenumber = RandRange(1,99999999) + now()>

 

Is there a more reliable way of doing this? 

 

Brian

 

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cfaussie+unsubscr...@googlegroups.com.
To post to this group, send email to cfaussie@googlegroups.com.
Visit this group at https://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"cfaussie" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cfaussie+unsubscr...@googlegroups.com.
To post to this group, send email to cfaussie@googlegroups.com.
Visit this group at https://groups.google.com/group/cfaussie.
For more options, visit https://groups.google.com/d/optout.

Reply via email to