sgzwiz / jillcode

Automatically exported from code.google.com/p/jillcode
Other
0 stars 1 forks source link

math.random(lower, upper) is broken #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Returns numbers outside of the given bounds, here's a fix.

http://code.google.com/p/jillcode/source/browse/code/mnj/lua/MathLib.java#284

case 2:   // lower and upper limits
        {
          int l = L.checkInt(1);
          int u = L.checkInt(2);
          L.argCheck(l<=u, 2, "interval is empty");
          L.pushNumber(rng.nextInt(1+u-l) + l); // FIX: to correct bounds
        }
        break;

Original issue reported on code.google.com by KrissD on 1 Jul 2010 at 2:07