Karl, sorry about this but I still don't get it?
>From what I get:
You have a set of M images somewhere all named img[digit].gif.
You have a set of N headlines.
You want to show each of the N headlines with an accompanying image where M
and N are arbitrary.
Now you don't care which image Y is shown with headline X as long as Y is
not show more than once? Correct? On top of that, you want that everytime
the page refreshes the order in which the images are shown must be
arbitrary, because otherwise there would be no need for using rand, just use
the currentRow number and you're all set.
What happens if there are more headlines than images? Do you show images
multiple times?
In any case, from what I stipulated you could do this:
iTotalImages = [the number of available images];
arrImageNames = new Array( recordCount ); // Array holding image names
for ( i=1; i LTE recordCount; i=i+1 ) {
inserted = false;
// Get an image number
while( !inserted ) {
iRandTmp = int( randRange( 1, recordCount ) ) ;
if ( iRandTmp GT iTotalImages ) {
iRandTmp = iRandTmp mod iTotalImages;
arrImageNames[i] = iRandTmp;
inserted = true;
}
else if ( !arrayFind( iRandTmp ) ) {
arrImageNames[i] = iRandTmp;
inserted = true;
}
} // end while
writeOutput( "<IMG SRC=""img#iRandTmp#"" ...> ... " );
} // end for
Marc
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Karl Zarudny
> Sent: Thursday, March 28, 2002 1:49 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [CFTALKTor] RandRange question - Unique random numbers
>
>
> Thanks Charlie and Mark.
>
> I'm basically trying to insert a random image for each record
> returned by my
> query. So for example:
>
> img1.gif - Headline1 - Mar. 28/2002.<br>
> img2.gif - Headline2 - Mar. 27/2002.<br>
> img3.gif - Headline3 - Mar. 26/2002.<br>
>
> Perhaps I'll need to do something with JS?
>
> Karl
>
> > From: "Marc Campeau" <[EMAIL PROTECTED]>
> > Reply-To: [EMAIL PROTECTED]
> > Date: Thu, 28 Mar 2002 12:40:54 -0500
> > To: <[EMAIL PROTECTED]>
> > Subject: RE: [CFTALKTor] RandRange question - Unique random numbers
> >
> > You could store randRange results in a list and do something like
> >
> > while ( listFind( randRangeResultList, n ) ) {
> > n = RandRange( 1, myquery.RecordCount );
> > }
> >
> > That in worst case could slow down your app though.
> >
> > A little more insight into what you want to achieve might help
> us provide
> > you with more help.
> >
> > Marc
> >
> >> -----Original Message-----
> >> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> >> Behalf Of Karl Zarudny
> >> Sent: Thursday, March 28, 2002 11:12 AM
> >> To: CFUG
> >> Subject: [CFTALKTor] RandRange question - Unique random numbers
> >>
> >>
> >> Hi everybody.
> >>
> >> I'm using RandRange to generate random numbers within a cfoutput.
> >> How can I
> >> ensure that there is no repetition? Here's what I'm doing:
> >>
> >> <cfoutput query="myquery">
> >> <cfset n = #RandRange(1,myquery.RecordCount)#>
> >> <img src="img#n#.gif" alt="Image #n#">
> >> </cfoutput>
> >>
> >> Should I be using something else instead?
> >>
> >> Thanks,
> >> Karl
> >>
> >> -
> >> You are subscribed to the CFUGToronto CFTALK ListSRV.
> >> This message has been posted by: Karl Zarudny
> <[EMAIL PROTECTED]>
> >> To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
> >> Manager: Kevin Towes ([EMAIL PROTECTED])
> >> http://www.CFUGToronto.org/
> >> This System has been donated by Infopreneur, Inc.
> >> (http://www.infopreneur.net)
> >>
> >>
> >
> > -
> > You are subscribed to the CFUGToronto CFTALK ListSRV.
> > This message has been posted by: "Marc Campeau" <[EMAIL PROTECTED]>
> > To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
> > Manager: Kevin Towes ([EMAIL PROTECTED])
http://www.CFUGToronto.org/
> This System has been donated by Infopreneur, Inc.
> (http://www.infopreneur.net)
-
You are subscribed to the CFUGToronto CFTALK ListSRV.
This message has been posted by: Karl Zarudny <[EMAIL PROTECTED]>
To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
Manager: Kevin Towes ([EMAIL PROTECTED]) http://www.CFUGToronto.org/
This System has been donated by Infopreneur, Inc.
(http://www.infopreneur.net)
-
You are subscribed to the CFUGToronto CFTALK ListSRV.
This message has been posted by: "Marc Campeau" <[EMAIL PROTECTED]>
To Unsubscribe, Please Visit and Login to http://www.CFUGToronto.org/
Manager: Kevin Towes ([EMAIL PROTECTED]) http://www.CFUGToronto.org/
This System has been donated by Infopreneur, Inc.
(http://www.infopreneur.net)