0

Sorry about the ambiguous title, I basically need to know how to use the choose function in java, to work out the chance of something happening, for example say I wanted to work out my chance of winning the lottery, on a calculator I'd do:

QUANTITY_OF_LOTTERY_NUMBERS CHOOSE 6

and that would return the chance of those six numbers appearing at random. I believe it's called the binomial theorem, but I dropped out of college before I could learn anything else about it :P

Anyway, if you do 49 choose 6 on Google for example, you'll see the function I'm trying to use

Question: How do I implement this function in Java code?

michaelok
  • 1,124
  • 1
  • 13
  • 20
Shaun Wild
  • 1,237
  • 3
  • 17
  • 34

1 Answers1

1

Apache Commons Math has it. If you are curious, you can read about Pascal's triangle.

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/util/CombinatoricsUtils.html#binomialCoefficient(int, int)

Petar Minchev
  • 46,889
  • 11
  • 103
  • 119