001 /** 002 * Implements the CFML Function randrange 003 */ 004 package railo.runtime.functions.math; 005 006 import railo.runtime.PageContext; 007 import railo.runtime.exp.ExpressionException; 008 import railo.runtime.ext.function.Function; 009 010 public final class RandRange implements Function { 011 public static double call(PageContext pc , double number1, double number2) throws ExpressionException { 012 return call(pc,number1,number2,"cfmx_compat"); 013 } 014 public static double call(PageContext pc , double number1, double number2, String algo) throws ExpressionException { 015 016 int min=(int) number1; 017 int max=(int) number2; 018 019 if(number1>number2) { 020 int tmp=min; 021 min=max; 022 max=tmp; 023 } 024 int diff=max-min; 025 return ((int)(Rand.call(pc,algo)*(diff+1)))+min; 026 } 027 028 public static int invoke(int min, int max) throws ExpressionException { 029 030 if(min>max) { 031 int tmp=min; 032 min=max; 033 max=tmp; 034 } 035 int diff=max-min; 036 return ((int)(Rand.call(null,"cfmx_compat")*(diff+1)))+min; 037 } 038 039 040 }