Randomize

Description

Seeds the random number generator in ColdFusion with the integer part of a number. By seeding the generator with a variable value, you help ensure that the Rand function generates highly random numbers.

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 in the range 0 - 1, it is not a random number, and you should not use it.

Example

<!--- 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 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" method = "POST">

<P>Enter a number to seed the randomizer:

<input type = "Text" name = "MyRandomInt">

<P><input type = "Submit" name = "">

</FORM>

</body>

</html>    



Banner.Novgorod.Ru