Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting 12 Random Numbers, But I don't want the number to repeat?

Status
Not open for further replies.

wrighterb

Programmer
Feb 20, 2007
80
US

Ok this works great below, I get 12 random numbers and populate a txt doc with information that I get from the database by the random number GREAT, one thing, I dont want the random number to repeat itself ever so each 12 numbers ( that I am getting from the ID field in the database ) have to be unique.

Any Ideas?

<cfquery name="RandomMeal" datasource="Spin4G">
SELECT Sum(1) AS rnum
FROM Thes
</cfquery>

<cfset thisNumber = 2>

<cfloop index="RandomMeal.ID" from="1" to="12">

<cfset R1 = RandRange(1,RandomMeal.rnum)>

<cfoutput>#R1#</cfoutput>

<cfquery datasource="Spin4G" name="List">
SELECT *
FROM Thes
Where WheelID = #R1# and Type = 'Blond'
</cfquery>

<cfif thisNumber gt 2>
<cfelse>
<cffile action="write" output="&Name1=#List.Name#&ImageLg1=#List.ImageLg#&Image1=#List.Image#&Link1=#List.Link#" file="#expandpath("SpinWheelTwelve.txt")#">
</cfif>

<cffile action="append" addnewline="yes" output="&Name#thisNumber#=#List.Name#&ImageLg#thisNumber#=#List.ImageLg#&Image#thisNumber#=#List.Image#&Link#thisNumber#=#List.Link#" file="#expandpath("SpinWheelTwelve.txt")#">

<cfset thisNumber = thisNumber + 1>

</cfloop>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top