Randomize

Description

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

Return value

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

Category

Mathematical functions

Syntax

Randomize(number)

See also

Rand, RandRange

Parameters

Parameter Description
number
A number

Usage

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

Example

<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>

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

Version 6

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

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt260.htm