A random number generator function is something that is available in many programming languages and that is missing yet in Jmol as far as I know.
It could be useful for example for simulations or minimizations to set random starting coordinates or other atom properties. (Something I actually would like to be able to do right now for a project without needing an external program.)
The function should be able to accept a seed value as parameter to be able to get reproducibly the same sequence of "random" numbers for some applications.
$ print random()
0.26415038
$ print random()
0.24874137
$ print random()
0.01516255
now documented as well.
For many applications (including my current one) it is important to be able to initialize the "random" number generator with a seed value to be able to reproduce the same sequence of values. In these cases "random" numbers rather means "automatically chosen sequence of arbitrary values".
Bob, would you consider adding a seed setting option?
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
Thank you very much!
however, I note that java.util.Random was never set up in JavaScript as anything more than JavaScript's Math.random(). Thus, it cannot be seeded. One possibility is to write a 32-bit random number generator rather than a 64-bit one.
http://chemapps.stolaf.edu/jmol/zip/jmol-14.3.12_2015.02.25b.zip
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
-- note that Java and JavaScript will have DIFFERENT seedings
-- utilizes https://github.com/davidbau/seedrandom/blob/released/seedrandom.js
(appended to java.util.Random.js)