random numbers

  • Jim Showalter
    Jim Showalter

    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.

    • 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);