tracker issue : CF-4203086

select a category, or use search below
(searches all categories and all time range)
Title:

RandRange returns wrong range for negative values

| View in Tracker

Status/Resolution/Reason: To Test//Fixed

Reporter/Name(from Bugbase): John Whish / ()

Created: 07/17/2018

Components: Language, Functions

Versions: 2016

Failure Type: Incorrectly functioning

Found In Build/Fixed In Build: ACF2018 /

Priority/Frequency: Normal / All users will encounter

Locale/System: / Platforms All

Vote Count: 1

Problem Description:

RandRange does not cope with negative ranges.

Steps to Reproduce:

{code:java}
<cfscript>
// RANGE -10 to -9

i = 0;
r = [];
while(i<10) {
    i++;
    r[i] = randRange(-10,-9);
}
    
writeDump(r); // outputs [-8,-8,-9,-8,-9,-9,-9,-8,-9,-8]

// RANGE -1 to 0

i = 0;
r = [];
while(i<10) {
    i++;
    r[i] = randRange(-1,0);
}
    
writeDump(r); // outputs [0,0,0,0,0,0,0,0,0,0]


// RANGE 0 to -1

i = 0;
r = [];
while(i<10) {
    i++;
    r[i] = randRange(0,-1);
}
    
writeDump(r); // outputs [0,0,0,0,0,0,0,0,0,0]
</cfscript>
{code}

Actual Result:

See inline comments on code above

Expected Result:

Integers within the specified range

Any Workarounds:

<cfscript>
int(0 - randRange(0,1));
</cfscript>

Attachments:

Comments:

+1 - completely agree this is a bug
Vote by Aaron Neff
29314 | July 17, 2018 09:29:39 AM GMT