<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>RANDOMIZE</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">RANDOMIZE</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Seeds the pseudo-random number generator with an integer number, ensuring repeatable number patterns. 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
A pseudo-random decimal number, in the range 0-1.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Mathematical functions, Security functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>Randomize(number[, algorithm])
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX&#160;7: Added the algorithm parameter.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
Rand, RandRange
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
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.
</p>

<p>
ColdFusion&#160;MX&#160;7 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, Macromedia cannot provide technical support for third-party security providers.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span>
<p>
The following example calls the Randomize function to seed the random number generator and generates 10 random numbers. To show the effect of the seed, submit the form with the same value multiple times.
</p>
<pre>&lt;h3&gt;Randomize Example&lt;/h3&gt;

   &lt;!--- Do the following only if the form has been submitted. ---&gt;
&lt;cfif IsDefined(&quot;Form.myRandomInt&quot;)&gt;

   &lt;!--- Make sure submitted value is a number and display its value. ---&gt;
   &lt;cfif IsNumeric(FORM.myRandomInt)&gt;
      &lt;cfoutput&gt;
         &lt;b&gt;Seed value is #FORM.myRandomInt#&lt;/b&gt;&lt;br&gt;
      &lt;/cfoutput&gt;&lt;br&gt;

      &lt;!--- Call Randomize to seed the random number generator. ---&gt;
      &lt;cfset r = Randomize(FORM.myRandomInt, &quot;SHA1PRNG&quot;)&gt;

      &lt;cfoutput&gt;
         &lt;b&gt;Random number returned by Randomize(#Form.myRandomInt#,
            &quot;SHA1PRNG&quot;):&lt;/b&gt;&lt;br&gt;
         #r#&lt;br&gt;
         &lt;br&gt;
         &lt;b&gt;10 random numbers generated using the SHA1PRNG algorithm:&lt;/b&gt;&lt;br&gt;
         &lt;cfloop index = &quot;i&quot; from = &quot;1&quot; to = &quot;10&quot; step = &quot;1&quot;&gt;
            #Rand(&quot;SHA1PRNG&quot;)#&lt;br&gt;
         &lt;/cfloop&gt;&lt;br&gt;
      &lt;/cfoutput&gt;

   &lt;cfelse&gt;
      &lt;p&gt;Please enter a number.
   &lt;/cfif&gt;
&lt;/cfif&gt;

&lt;!--- Form to specify the seed value. ---&gt;
&lt;form action=&quot;#CGI.SCRIPT_NAME#&quot; method=&quot;post&quot;&gt;
&lt;p&gt;Enter a number to seed the randomizer:
&lt;input type = &quot;Text&quot; name = &quot;MyRandomInt&quot; value=&quot;12345&quot;&gt;
&lt;p&gt;&lt;input type = &quot;Submit&quot; name = &quot;&quot;&gt;
&lt;/form&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="NUMBER">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">NUMBER</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


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

  </td>
  </tr>
  </table>
</div>
<div id="ALGORITHM">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">ALGORITHM</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>(Optional) The algorithm to use to generate the seed number. ColdFusion MX installs a cryptography library with the following algorithms:</p><ul>

<li>CFMX_COMPAT: the algorithm used in ColdFusion MX (default).</li>

<li>SHA1PRNG: generates a number using the Sun Java SHA1PRNG algorithm. This algorithm provides greater randomness than the default algorithm.</li>

<li>IBMSecureRandom: for IBM WebSphere (IBM JVM does not support the SHA1PRNG algorithm).</li>
</ul>


  </td>
  </tr>
  </table>
</div>

  </body>
</html>
