[thelist] RE: (answer) Randomizing Question

Palyne Gaenir palyne at sciencehorizon.com
Wed Nov 29 23:28:16 CST 2000

Whoops, sorry Ryan, and thanks tons for your help.  Folks Ryan sent 
me the complete semi-randomization code (see bottom of msg).

fwiw I translated your

  Declare @Random int
  Set @Random Rand() * 10000

  <CFSET RNUM1 = "#RandRange(1,289)#">
  <CFSET RNUM2 = "(#RNUM1# * #RandRange(6,3964)#)">

and your
  Order By Rand(@Random * Ascii(table.charField))

  ORDER BY Rand(#RNUM2# * Ascii(Right(table.TXTFIELD,2)))

...and it appears to work really well.  A little arbitrary in my 
numbering I suppose, but oh well. :-)  Many thanks again.  

(Ryan's code is below.)

> On 30 Nov 2000, at 0:10, Ryan Trudelle-Schwarz wrote:

Could you please forward this to the list so they 
don't all think i'm dumb :)

It was mischopped in the reference to you. The KEY idea is to 
generate a random value outside of your select statement:  

  Declare @Random int
  Set @Random Rand() * 10000

Then when you use it within your select:

  Order By Rand(@Random * table.idField)

it will sometimes come up randomly. To get it to come up randomly most of
the time (nothings perfect ok?) use a character field's ascii value:

  Order By Rand(@Random * Ascii(table.charField))

Play with which field you use and you can use Right to move to different
locations within the field to do the ascii on.

With proper testing, you can achieve fairly random results.

hth, Ryan

           ASP Code Samples

More information about the thelist mailing list