Revision: 20332
          http://sourceforge.net/p/jmol/code/20332
Author:   hansonr
Date:     2015-02-25 18:38:17 +0000 (Wed, 25 Feb 2015)
Log Message:
-----------
mol.___JmolVersion="14.3.12_2015.02.25b"

new feature: random(low,high,seed)
 -- provides a new seed for the random() function
 -- seed may be any 48-bit integer. 
 -- x = random(0.0,1.0,121231223)
 -- low and high are simply placeholders
 -- does return the first number from this seed
 

Modified Paths:
--------------
    trunk/Jmol/src/org/jmol/script/T.java
    trunk/Jmol/src/org/jmol/scriptext/MathExt.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties

Modified: trunk/Jmol/src/org/jmol/script/T.java
===================================================================
--- trunk/Jmol/src/org/jmol/script/T.java       2015-02-25 18:00:56 UTC (rev 
20331)
+++ trunk/Jmol/src/org/jmol/script/T.java       2015-02-25 18:38:17 UTC (rev 
20332)
@@ -756,7 +756,6 @@
   
   public final static int cross = 1 | 2 << 9 | mathfunc;
   public final static int load         = 3 | 2 << 9 | mathfunc | scriptCommand;
-  public final static int random       = 4 | 2 << 9 | mathfunc;
   public final static int script       = 5 | 2 << 9 | mathfunc | scriptCommand;
   public final static int substructure = 6 | 2 << 9 | mathfunc | intproperty | 
strproperty;
   public final static int search       = 7 | 2 << 9 | mathfunc;
@@ -783,7 +782,8 @@
   public final static int hkl          = 1 | 3 << 9 | mathfunc;
   public final static int intersection = 2 | 3 << 9 | mathfunc;
   public final static int prompt       = 3 | 3 << 9 | mathfunc | 
mathExpressionCommand;
-  public final static int select       = 4 | 3 << 9 | mathfunc | 
atomExpressionCommand;
+  public final static int random       = 4 | 3 << 9 | mathfunc;
+  public final static int select       = 5 | 3 << 9 | mathfunc | 
atomExpressionCommand;
 
   // ___.xxx(a,b,c)
   

Modified: trunk/Jmol/src/org/jmol/scriptext/MathExt.java
===================================================================
--- trunk/Jmol/src/org/jmol/scriptext/MathExt.java      2015-02-25 18:00:56 UTC 
(rev 20331)
+++ trunk/Jmol/src/org/jmol/scriptext/MathExt.java      2015-02-25 18:38:17 UTC 
(rev 20332)
@@ -26,6 +26,7 @@
 
 import java.util.Date;
 import java.util.Map;
+import java.util.Random;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -2056,12 +2057,30 @@
     return mp.addXPt4((q == null ? Quat.newP4(p4) : q).toPoint4f());
   }
 
+  private Random rand;
+
   private boolean evaluateRandom(ScriptMathProcessor mp, SV[] args) {
-    if (args.length > 2)
+    if (args.length > 3)
       return false;
-    float lower = (args.length < 2 ? 0 : SV.fValue(args[0]));
-    float range = (args.length == 0 ? 1 : SV.fValue(args[args.length - 1])) - 
lower;
-    return mp.addXFloat((float) (Math.random() * range) + lower);
+    if (rand == null)
+      rand = new Random();
+    float lower = 0, upper = 1, seed = Float.NaN;
+    switch (args.length) {
+    case 3:
+      rand.setSeed((int) SV.fValue(args[2]));
+      //$FALL-THROUGH$
+    case 2:
+      upper = SV.fValue(args[1]);
+      //$FALL-THROUGH$
+    case 1:
+      lower = SV.fValue(args[0]);
+      //$FALL-THROUGH$
+    case 0:
+      break;
+    default:
+      return false;
+    }
+    return mp.addXFloat((rand.nextFloat() * (upper - lower)) + lower);
   }
 
   private boolean evaluateRowCol(ScriptMathProcessor mp, SV[] args, int tok)

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-02-25 18:00:56 UTC 
(rev 20331)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-02-25 18:38:17 UTC 
(rev 20332)
@@ -14,8 +14,17 @@
 
 TODO: remove HTML5 dependency on synchronous file loading (check SCRIPT 
command for problems)
 
-Jmol.___JmolVersion="14.3.12_2015.02.25"
+Jmol.___JmolVersion="14.3.12_2015.02.25b"
 
+new feature: random(low,high,seed)
+ -- provides a new seed for the random() function
+ -- seed may be any 48-bit integer. 
+ -- x = random(0.0,1.0,121231223)
+ -- low and high are simply placeholders
+ -- does return the first number from this seed
+ 
+JmolVersion="14.3.12_2015.02.25"
+
 new feature: show chemical drawing
 new feature: show drawing
  -- pops up window with drawing of model

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to