View comments | RSS feed
Contents > CFML Reference > ColdFusion Functions > Randomize PreviousNext

Randomize

Seeds the ColdFusion random number generator with an integer number. Seeding the generator helps ensure that the Rand function generates highly random numbers.

A non-random decimal number, in the range 0 - 1.

Mathematical functions

Randomize(number)

Rand, RandRange

Parameter

Description

number

A number

Call this function before calling Rand. Although this function returns a decimal number, it is not a random number.

<h3>Randomize Example</h3>
<p>Call Randomize to seed the random number generator. This helps 
to ensure the randomness of numbers generated by Rand. <cfif IsDefined("FORM.myRandomInt")> <cfif IsNumeric(FORM.myRandomInt)> <cfoutput><p><b>Seed value is #FORM.myRandomInt#</b> </cfoutput><br> <cfset r = Randomize(FORM.myRandomInt)> <cfloop index = "i" from = "1" to = "10" step = "1"> <cfoutput>Next random number is #Rand()#</cfoutput><br> </cfloop><br> <cfelse> <p>Please enter a number. </cfif> </cfif> <form action = "randomize.cfm"> <p>Enter a number to seed the randomizer: <input type = "Text" name = "MyRandomInt"> <p><input type = "Submit" name = ""> </form>

Contents > CFML Reference > ColdFusion Functions > Randomize PreviousNext

ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


No screen name said on Nov 27, 2003 at 2:36 AM :
This function does no longer work with GetTickCount() as a parameter since it does only take integers as parameter. In CF 5 samples GetTickCount was often used to initialize the randomize function.
Terry Luedtke said on Sep 21, 2004 at 2:58 PM :
You could try something like randomize(right(getTickCount(), 9)).
bizarrojack said on Jan 6, 2005 at 9:12 AM :
Getting a truly random number isn't easy. This macromedia blog entry should be of use to anyone who is using rand.

http://www.markme.com/cantrell/archives/004256.cfm
Thank you Christian Cantrell!

Since I am java-phobic, though, if anyone knows how to seed the PRNG with something from PRNGD or EGD or a /dev/random, I'd love to see that.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/functa61.htm