Well, without getting into a semantics argument over the use of the word
"random".....

The previous code I was using:

<cfparam name="imageswap" default="#randrange(1,7)#">

...if tested 50 times in a row was ONLY returning the first three images. I
never saw 4,5,6 or 7 at all, either locally or out live on the server. Seems
weighted towards the first three numbers and obviously, not nearly random
enough.

Now I'm using the code below to generate the numbers (Thanks Mark).  It
works quite well.
***************************************************************
<!-- begin  -->

<cfapplication name="randrange" clientmanagement="Yes"
sessionmanagement="Yes" setclientcookies="Yes" clientstorage="Registry">

<cfparam name="session.randrangelist" default="">

<cfset newnum = RandRange(1,7)>

<cfloop condition="session.randrangelist contains newnum">
        <cfset newnum = RandRange(1,7)>
</cfloop>

<cfset session.randrangelist = "#ListAppend(session.randrangelist,
newnum)#">

<cfoutput>
List: #session.randrangelist#<br>
Current Random Number: #newnum#
</cfoutput>

<cfif ListLen(session.randrangelist) gt 6>
        <cfset session.randrangelist = "">
</cfif>
<!-- end  -->
************************************************************

However, I've always believed that the less code to accomplish a task, the
better.  So, I query on....

Not quite as many lines as the JavaScript I was hoping to avoid, but a hell
of a lot more than the few lines I was using.  JavaScript looks like (I did
*NOT* write this from scratch.....):

function rand(n) {
seed=(0x015a4e35 * seed) % 0xffffff;
return (seed >> 16) % n;
var now = new Date()
var seed = now.getTime()%0xffffff

Basically this gets the seed from the current time in milliseconds...blah,
blah, until it comes up with random numbers between zero and your number.
Then you define an array.....

var images = new makeAray(7);
image[0]= "foo"...and so on

plus a document write statement that pulls from the array......

document.write(images[rand(images.length)])

....and the whole shebang ends up being a pretty big chunk of code.   ;-p

So, back to my original chunk:

<cfparam name="imageswap" default="#randrange(1,7)#">

How would you seed this and get it more "random" and yet as compact code
wise as possible? (I see a custom tag in the making......)  To be honest,
it's probably that I don't understand quite enough about "seeding" to start
with, although thanks to you folks fine answers I'm starting to get the gist
of it.



Les Mizzell
***********
Some people say I'm too apathetic.
But why should I care?

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to