Randomize

Description

Seeds the pseudo-random number generator with an integer number, ensuring repeatable number patterns.

Returns

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

Category

Mathematical functionsSecurity functions

Function syntax

Randomize(number[, algorithm])

History

  • ColdFusion (2023 release) Update 8 and ColdFusion (2021 release) Update 14: Changed the default algorithm from CFMX_COMPAT to SHA1PRNG.
  • ColdFusion MX 7: Added the algorithm parameter.

See also

RandRandRange

Parameters

Parameter

Description

number

Integer number. If the number is not in the range -2,147,483,648 -2,147,483,647, ColdFusion generates an error.

algorithm

(Optional) The algorithm to use to generate the seed number. ColdFusion installs a cryptography library with the following algorithms:

  • CFMX_COMPAT: the algorithm used in ColdFusion.
  • SHA1PRNG: generates a number using the Sun Java SHA1PRNG algorithm. This algorithm provides greater randomness than the default algorithm. Note: due to a bug in ColdFusion 9, 10 and 11, this option does not work as prescribed. See bug 3792283 for details. (Default)
  • IBMSecureRandom: for IBM WebSphere (IBM JVM does not support the SHA1PRNG algorithm).

Usage

Call this function before calling Rand 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.In Standard Edition, for all algorithms except the default algorithm, ColdFusion uses the Java Cryptography Extension (JCE) and installs a Sun Java runtime that includes the Sun JCE default security provider. This provider includes the algorithms listed in the Parameters section. The JCE framework includes facilities for using other provider implementations; however, Adobe cannot provide technical support for third-party security providers.In Enterprise Edition, ColdFusion also installs the RSA BSafe Crypto-J library. This provider adds the following algorithms: FIPS186PRNG, MD5PRNG, DummyPRNG, OBFPRNG. DummyPRNG always returns 0.

Note: To get repeatable number of patterns for a given initial seed, JSAFE must be disabled using the JVM argument on enterprise and developer editions as follows:

Dcoldfusion.disablejsafe=true

Example

The following example calls the Randomize function to seed the random number generator and generates 10 random numbers. 

<cfset randomize(12345)> <!--- if one was to remove this line, the random numbers are different every time --->
<cfloop index="i" from="1" to="10">
<cfoutput>#rand()#</cfoutput><br>
</cfloop>

 Adobe

Получайте помощь быстрее и проще

Новый пользователь?

Adobe MAX 2024

Adobe MAX
— творческая конференция

С 14 по 16 октября очно в Майами-Бич и онлайн

Adobe MAX

Творческая конференция

С 14 по 16 октября очно в Майами-Бич и онлайн

Adobe MAX 2024

Adobe MAX
— творческая конференция

С 14 по 16 октября очно в Майами-Бич и онлайн

Adobe MAX

Творческая конференция

С 14 по 16 октября очно в Майами-Бич и онлайн