rand
Description
Generates a pseudo-random number.
Categories
Related
History
ColdFusion
MX 7: Added the algorithm parameter.
Syntax
Rand([algorithm])
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| algorithm | (Optional) The algorithm to use to generate the random number. ColdFusion installs a cryptography library with the following algorithms: CFMX_COMPAT: the algorithm used in ColdFusion (default). SHA1PRNG: generates a number using the Sun Java SHA1PRNG algorithm. This algorithm provides greater randomness than the default algorithm IBMSecureRandom: for IBM WebSphere (IBM JVM does not support the SHA1PRNG algorithm). |
Returns
A pseudo-random
decimal number, in the range 0 – 1.
Usage
Call the Randomize function before calling this function to seed the random number generator. Seeding the generator ensures that the Rand function always generates the same sequence of pseudo-random numbers. This behavior is useful if you must reproduce a pattern consistently.
ColdFusion MX uses the Java Cryptography Extension (JCE) and installs a Sun Java 1.4.2 runtime that includes the Sun JCE default security provider. This provider includes the algorithms listed in the Parameters section (except the default algorithm). The JCE framework includes facilities for using other provider implementations; however, cannot provide technical support for third-party security providers.
ColdFusion MX uses the Java Cryptography Extension (JCE) and installs a Sun Java 1.4.2 runtime that includes the Sun JCE default security provider. This provider includes the algorithms listed in the Parameters section (except the default algorithm). The JCE framework includes facilities for using other provider implementations; however, cannot provide technical support for third-party security providers.
Example
The
following example uses the SHA1PRNG algorithm to generate a single random
number:
<h3>Rand Example</h3>
<cfoutput>
Rand("SHA1PRNG") returned: #Rand("SHA1PRNG")#</p>
<A HREF = "#CGI.SCRIPT_NAME#">Try again</A>
</cfoutput>