Menu

#220 Random number generator function

v10
closed-fixed
nobody
None
5
2019-04-27
2015-02-25
Rolf Huehne
No

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.

Discussion

  • Bob Hanson

    Bob Hanson - 2015-02-25

    $ print random()
    0.26415038
    $ print random()
    0.24874137
    $ print random()
    0.01516255

     
  • Bob Hanson

    Bob Hanson - 2015-02-25

    now documented as well.

     
  • Rolf Huehne

    Rolf Huehne - 2015-02-25

    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?

     
  • Bob Hanson

    Bob Hanson - 2015-02-25

    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

     
  • Rolf Huehne

    Rolf Huehne - 2015-02-25

    Thank you very much!

     
  • Bob Hanson

    Bob Hanson - 2015-02-25

    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.

     
  • Bob Hanson

    Bob Hanson - 2015-02-25

    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)

     
  • Angel Herraez

    Angel Herraez - 2019-04-27
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB