random numbers

2005-11-11
2013-04-30
  • Jim Showalter

    Jim Showalter - 2005-11-11

    Would it be possible to implement a random number generator in a Jin bean shell?   Low-level pseudo-randoms would be fine, so it should not have much overhead.

     
    • Alexander Maryanovsky

      Well, you kind of have to know Java if you're going to write anything but the most simple scripts. You can use Math.random() which returns a random value between 0 and 1, then multiply it by N and round down to get a random number between 0 and N. It would look like this:
      int n = (int)(Math.random()*N);

       

Log in to post a comment.