Mercurial Hosting > luan
diff core/src/luan/modules/MathLuan.java @ 244:0a8e6fdb62f0
fix Math.random()
git-svn-id: https://luan-java.googlecode.com/svn/trunk@245 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 09 Oct 2014 22:44:07 +0000 |
parents | ec016471c6eb |
children | 58752e3e4c5c |
line wrap: on
line diff
--- a/core/src/luan/modules/MathLuan.java Wed Oct 08 06:22:04 2014 +0000 +++ b/core/src/luan/modules/MathLuan.java Thu Oct 09 22:44:07 2014 +0000 @@ -32,7 +32,7 @@ module.put("pi",Math.PI); add( module, "pow", Double.TYPE, Double.TYPE ); add( module, "rad", Double.TYPE ); - add( module, "random" ); + add( module, "random", Integer.class, Integer.class ); add( module, "sin", Double.TYPE ); add( module, "sinh", Double.TYPE ); add( module, "sqrt", Double.TYPE ); @@ -126,8 +126,12 @@ return Math.toRadians(x); } - public static double random() { - return Math.random(); + public static double random(Integer m,Integer n) { + if( m==null ) + return Math.random(); + if( n==null ) + return Math.floor(m*Math.random()) + 1; + return Math.floor((n-m)*Math.random()) + m; } public static double sin(double x) {