vendredi 25 octobre 2019

A method for long datatype similar to nextInt(int bound) of Java Random Class

I need a method similar to nextInt(int bound) of Java Random Class for long data type. Here is my implementation:

   static long randomLong(Random rNumber, long bound)
   {
      long z = rNumber.nextLong();

      return (z % bound);
   }

Where rNumber is initialized from the calling method as,

Random rNumber = new Random();

My question is, does this implementation ensures a pseudorandom, uniformly distributed long value between 0 (inclusive) and the bound (exclusive) ?




Aucun commentaire:

Enregistrer un commentaire