as a side note:
The topic of pseudo random number generation has long been of interest to
many.
You can probably assume that no small sampling will deliver a truly uniform
set...without controlling the seed.
As a customer, It would bother me if my "opportunities" were not delivered
in a judicious manner.
I suggest the following:
- Read a saved seed.
- Create a scoreboard to log the values pulled.
- Save that resulting seed off to use next time.
Run a representive number of cases and examine the scoreboard to see if
there is a bias.
- If you notice a bias, be prepared to code your own.
The following book discusses random number generation in a fairly good
manner. [It is dated and the algorithms are expressed in FORTRAN IV, but a
quality reference that has stood the test of time.]
Law, Averill M, and Kelton, W. David. 1991
Simulation Modeling & Analysis, Second edition
McGraw Hill, New York
good luck,
jack lavender
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
Behalf Of Dan Slater
Sent: Wednesday, July 18, 2001 4:31 PM
To: [EMAIL PROTECTED]
Subject: Random Numbers and CFLOOP
Hi all,
Got me a stumper here, the more I look at it, the more I believe there's
nothing wrong. Yet the page seems to be caught in an infinite (or extremely
stubborn) cfloop
Let me splain: I'm developing a shopping mall that needs to always show 5
random stores. That part was simple, getting CF to NOT repeat a random
number that was already generated is where i'm having difficulty.
First I query the stores table to get a "list of IDs":
<cfquery name="getStores" datasource="#DSN3#">
SELECT pkStoreID
FROM tblStores
WHERE tblStores.TierID = 4
</cfquery>
Then I create a random number using the results of the above query to set
the range. After that I loop through a new query and set the endrow to =
the amount of records in the above query. Then I output the single record
returned in a row of a HTML table. At the end of the loop, i create a new
variable and set it to the current "Random" number. For each iteration of
the loop, I check to see if the currently generated random number is EQ the
previous iteration's random number. If EQ, keep setting the random number
until NEQ. Wash, Rinse, Repeat until the "endrow" of the outer CFLOOP is
reached:
<CFSET temp = ValueList(getStores.pkStoreID)>
<CFSET tempnum = #ListLen(temp)#>
<CFOUTPUT>
<table border="0" align="center" width="100%">
<tr>
<cfset NewNum = 0>
<cfloop query="getStores" startrow="1" endrow="#getStores.RecordCount#">
<CFSET randtemp = #RandRange(1,tempnum)#>
<CFSET #RANDNUMBER# = #ListGetAt(temp, randtemp)#>
<cfloop condition="#NewNum# EQ #RANDNUMBER#">
<CFSET #RANDNUMBER# = #ListGetAt(temp, randtemp)#>
</cfloop>
<cfquery name="qryStores" datasource="#DSN3#">
SELECT tblStores.pkStoreID, tblStores.StoreName,
tblStores.StoreDesc, tblStores.StoreLogo,
tblStores.URL, tblStores.TierID, tblSubCategories.CatID,
tblSubCategories.pkSubCatID
FROM tblStores
INNER JOIN tblStoresSubCatsLink ON tblStores.pkStoreID =
tblStoresSubCatsLink.StoreID
INNER JOIN tblSubCategories ON tblStoresSubCatsLink.SubCatID =
tblSubCategories.pkSubCatID
WHERE tblStores.pkStoreID = #RANDNUMBER#
</cfquery>
<td>
<a href="store.cfm?StoreID=#qryStores.pkStoreID#">
<img src="merchants/images/logolarge/#qryStores.StoreLogo#.jpg"
border="0" height="125" width="125">
</a>
</td>
<td valign="top">
#qryStores.StoreDesc#...
<a href="store.cfm?StoreID=#qryStores.pkStoreID#" class="ShopNow">SHOP
NOW</a>
</td>
</tr>
<tr>
<td colspan="2"><hr></td>
</tr>
<cfset NewNum = #RANDNUMBER#>
</cfloop>
</tr>
</table>
</CFOUTPUT>
BTW, the query returns two total records, so the loop has to loop thru 1 or
2 only to create a random number not equal to the intial random number. I
don't understand why it would basically lock up CF when run.
Am I missing something obvious here? Please help, my deadline is fast
approaching and this is slowing me WAY down.
Respectfully,
Dan Slater
-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org
-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com
-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org