mike tangorre whipped this up, and this returns niceness, no dupes.

good stuff tango

<cfset session.objRandomGenerator =
CreateObject("component","randomGenerator") />
<cfoutput>
<cfloop from = 1 to = 50 index = i>
#session.objRandomGenerator.next()# <BR>
</cfloop>
</cfoutput>



-----Original Message-----
From: Tony Weeg [mailto:[EMAIL PROTECTED]
Sent: Monday, January 26, 2004 11:37 AM
To: CF-Talk
Subject: RE: random number cfc

sure...this is christians code from his blog...so, I wonder what he thinks?

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, January 26, 2004 11:35 AM
To: CF-Talk
Subject: RE: random number cfc

have a look at http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html
maybe reseed on each iteration?  


Doug

-----Original Message-----
From: Tony Weeg [mailto:[EMAIL PROTECTED]
Sent: Monday, January 26, 2004 11:28 AM
To: CF-Talk
Subject: RE: random number cfc

so cf is looping 5 times per second...on average?

and therefore on the same getTickCount() tick?

tw

-----Original Message-----
From: Adrian Lynch [mailto:[EMAIL PROTECTED]
Sent: Monday, January 26, 2004 11:27 AM
To: CF-Talk
Subject: RE: random number cfc

Nope, but the seed for Random() in Java is most likely the system clock.
Your loop is too fast for it. Sorry I don't have a solution for you, no
doubt someone will.

Ade

-----Original Message-----
From: Tony Weeg [mailto:[EMAIL PROTECTED]
Sent: 26 January 2004 16:20
To: CF-Talk
Subject: random number cfc

<cfobject name="randomGenerator" component="randomGenerator"> <cfoutput>
<cfloop from = 1 to = 50 index = i> <cfinvoke component="randomGenerator"
method="next"
returnvariable="theNumber">
#theNumber#<BR>
</cfloop>
</cfoutput>

Is what I have, and here are the results, am I doing something wrong?

3582162
3582162
3582162
3582162
3582162
3582162
87279085
87279085
87279085
87279085
87279085
90357076
90357076
90357076
90357076
90357076
90357076
81123102
81123102
81123102
81123102
81123102
85162966
85162966
85162966
85162966
85162966
85162966
75928992
79006983
79006983
69965384
69965384
69965384
69965384
69965384
73043375
73043375
73043375
73043375
73043375
73043375
12480138
12480138
12480138
12480138
12480138
15558129
15558129
15558129

and here is the code in the cfc

<cfcomponent output="no">

    <cfset my = structNew()/>
    <cfset my.rnd = createObject("java", "java.util.Random").init()/>
    <cfset my.min = 0/>
    <cfset my.max = 99999999/>
    <cfset my.cnt = 0/>

    <!-- Set the minimum and maximum. --->
    <cffunction name="setBounds" access="public" returnType="void"
output="no">
        <cfargument name="min" type="numeric" required="true"/>
        <cfargument name="max" type="numeric" required="true"/>
        <cfset my.min = arguments.min/>
        <cfset my.max = arguments.max/>
    </cffunction>

    <!--- Set the maximum.  The minimum is automatically 0. --->
    <cffunction name="setMax" access="public" returnType="void" output="no">
        <cfargument name="max" type="numeric" required="true"/>
        <cfset my.max = arguments.max/>
    </cffunction>

    <!--- Sets the seed.  Accepts ints and longs (but no decimals). --->
    <cffunction name="setSeed" access="public" returnType="void"
output="no">
        <cfargument name="seed" type="string" required="true"/>
        <cfset var l = createObject("java",
"java.lang.Long").init(arguments.seed)/>
        <cfset my.rnd.setSeed(l.longValue())/>
    </cffunction>

    <!--- Returns the next highly random number. --->
    <cffunction name="next" access="public" returnType="numeric"
output="no">
        <cfif my.min + my.max eq 0>
            <cfreturn my.rnd.nextInt()/>
        <cfelse>
            <cfreturn (my.rnd.nextInt(javaCast("int",((my.max+1) - my.min)))
+ my.min)/>
        </cfif>
    </cffunction>

    <!--- Returns a random boolean. --->
    <cffunction name="nextBoolean" access="public" returnType="boolean"
output="no">
        <cfreturn my.rnd.nextBoolean()/>
    </cffunction>

</cfcomponent>
  _____
  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to