-4

Using the Well512 random number generator class in Java, how can one generate a random number with a range like 0 to 50?

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
user79235
  • 19
  • 1
  • 3
  • 2
    What does documentation say? – nolexa Feb 22 '16 at 21:32
  • 4
    The WELL512 RNG is a type of random number generator. It is not included in the Java library. There, however, exist implementations in third-party libraries like Apache Commons. – ifly6 Feb 22 '16 at 21:46
  • @Brandon I don't think that covers the WELL512 RNG – River Feb 22 '16 at 21:59
  • @AndrewRegan if a post isn't a [good question](https://stackoverflow.com/help/how-to-ask) many users will downvote it. For that matter, you should also avoid [answering questions have already been asked and answered many times before](https://stackoverflow.com/help/how-to-answer). – DavidS Feb 22 '16 at 22:59
  • OP has a question about a specific RNG, part of a particular library with a distinct API. I don't know why people seem to have missed/ignored that and assumed he was just a newbie asking about Math.random() and Random, which is what Brandon's link is all about. – Andrew Regan Feb 22 '16 at 23:01
  • When the answer is "read the JavaDoc", that's a poor question, @AndrewRegan. The first comment also asks "What have you tried yourself", which is another reason this is a poor question. Even if the `nextInt(int)` method didn't exist, a programmer should be capable of trying something himself. – DavidS Feb 22 '16 at 23:06
  • I think that's harsh, and that Well512 is rare enough (only 9 questions here) for people to not jump on the bandwagon and try to get it closed it down. – Andrew Regan Feb 22 '16 at 23:10

1 Answers1

0

For the simplest case (default seed, once only):

new org.apache.commons.math3.random.Well512a().nextInt(50);

Though you'll doubtless want to store that instance and reuse it.

See: https://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/random/Well512a.html.

Well512a implements https://commons.apache.org/proper/commons-math/javadocs/api-3.6/org/apache/commons/math3/random/BitsStreamGenerator.html

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73