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

randRange Argument Reference

number1
Required

number2
Required

algorithm
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


Tag Example

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> 
 </cfif>  

Tag Example

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

Fork me on GitHub