Chapter 2: ColdFusion Functions
Randomize
Seeds the random number generator in ColdFusion with the integer part of a number.
By seeding the random number generator with a variable value, you help to ensure
that the Rand function generates highly random numbers.
See also
Syntax
Randomize( number )
number
Any number.
Usage
Call this function before calling Rand. Although this function returns a decimal
number in the range 0 to 1, it is not a random number and you should not use it.
Examples
<!--- This example shows the use of Randomize --->
<HTML>
<HEAD>
<TITLE>
Randomize Example
</TITLE>
</HEAD>
<BODY BGCOLOR=silver>
<H3>Randomize Example</H3>
<P>Call Randomize to seed the random number generator.
This helps to ensure the randomness of numbers generated
by the Rand function.
<CFIF IsDefined("FORM.myRandomInt")>
<CFIF IsNumeric(FORM.myRandomInt)>
<CFELSE>
</CFIF>
</CFIF>
<FORM ACTION="randomize.cfm" METHOD="POST">
<P>Enter a number to seed the randomizer:
<INPUT TYPE="Text" NAME="MyRandomInt">
<P><INPUT TYPE="Submit" NAME="">
</FORM>
</BODY>
</HTML>
Rand
and RandRange.
<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>
<P>Please enter a number.
489
Need help?
Do you have a question about the COLDFUSION 4.5-CFML LANGUAGE and is the answer not in the manual?
Questions and answers