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 Rand and RandRange.

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)>
        <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" METHOD="POST">
<P>Enter a number to seed the randomizer:
<INPUT TYPE="Text" NAME="MyRandomInt">
<P><INPUT TYPE="Submit" NAME="">
</FORM>

</BODY>
</HTML>