randRange

Generates a random integer between two specified numbers.
Requests for random integers that are greater than 100,000,000
result in non-random numbers, to prevent overflow during
internal computations.

randRange(number1, number2 [, algorithm]) → returns numeric

Argument Reference

number1 numeric
Required

number2 numeric
Required

algorithm string
Default: CFMX_COMPAT

CF 7+ The algorithm to use to generated the random number.
Values:
  • CFMX_COMPAT
  • SHA1PRNG
  • IBMSecureRandom
  • NativePRNG
  • NativePRNGBlocking
  • NativePRNGNonBlocking

Links more information about randRange

Examples
Sample code invoking the randRange function

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

<cfset r = randomize(7, "SHA1PRNG")> 
 <cfset local.myInt = 1 /> 
 <cfset local.myInt2 = 999 /> 
<!--- Generate and display the random number. ---> 
 <cfoutput><p><b> 
 RandRange returned: #randRange(local.myInt, local.myInt2, "SHA1PRNG")# 
 </cfoutput></b></p>  

<cfscript> 
 bytes = []; 
 bytecount = 32; 
 arrayResize( bytes, byteCount ); 
 for (  i = 1 ; i <= byteCount ; i++ ) { 
  bytes[ i ] = randRange( -128, 127, "SHA1PRNG" ); 
         } 
 </cfscript> 
 <cfdump var="#bytes#" />  

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub