34
3
Powerball is an American lottery that has recently gained attention because the current jackpot (as of January 11, 2016) is the largest lotto prize in history, at about $1.5 billion (USD).
Powerball players choose 5 distinct numbers from 69 numbered white balls, and 1 one "Powerball" number from 26 numbered red balls. They win the jackpot if their five white ball choices match what was drawn in any order, and if they chose the correct "Powerball" number.
So the chances of winning the jackpot are 1 in (69 choose 5)*(26 choose 1)
or ((69*68*67*66*65)/(5*4*3*2*1))*26
, which is 1 in 292,201,338
No one won the jackpot in the most recent drawing on January 9, 2016, but perhaps someone will win the next drawing on January 13, 2016, 10:59 pm ET.
Challenge
Write a program or function that simulates a Powerball drawing, taking no input but outputting 5 distinct random numbers from 1 to 69 inclusive, and then one random "Powerball" number from 1 to 26 inclusive (which could be a repeat of one of the 5 initial numbers).
The "Powerball" number should always be the last number in the output, but otherwise the order of the first 5 numbers does not matter.
The 6 numbers should be output in decimal, either space separated or newline separated, with an optional single trailing newline. Commas, brackets, and other characters are not allowed in the output.
So these would be valid outputs (using the numbers from the last drawing):
32 16 19 57 34 13
32
16
19
57
34
13
All 292201338 possible outcomes should be possible with uniform probability. You may use built-in pseudo-random number generators and assume they meet this standard.
Here is an ungolfed reference implementation that works in Python 2 or 3:
import random
print(' '.join(map(str, random.sample(range(1,70), 5) + [random.randint(1, 26)])))
The shortest code in bytes wins.
Note that I have no affiliation with Powerball and don't really suggest that you play. But if you win anything from numbers generated by one of the programs here, I'm sure we'd love to hear about it. :D
12Missed opportunity to demand a share of the winnings should someone here get the jackpot. – Alex A. – 2016-01-12T03:07:35.683
Do the 5 numbers have to be in order? – Neil – 2016-01-12T13:37:42.440
@Neil "The "Powerball" number should always be the last number in the output, but otherwise the order of the first 5 numbers does not matter." – Calvin's Hobbies – 2016-01-12T13:39:04.413
3I'm sure no one is confused, but you actually mean integers in the challenge. – jpmc26 – 2016-01-12T14:40:17.587
Some proposed "solutions" would appear to a substantial likelihood of including duplicates in the output; that should of course be forbidden. – supercat – 2016-01-13T21:25:58.287
@supercat The "Powerball" can be a duplicate of one of the others. The first 5 numbers should be unique. – Brad Gilbert b2gills – 2016-01-13T21:30:42.833
Can a function return a list of values? Also can the first 5 be in a sub list, followed by a single value for the Powerball? – Brad Gilbert b2gills – 2016-01-13T21:34:30.540
@BradGilbertb2gills No. "The 6 numbers should be output in decimal, either space separated or newline separated, with an optional single trailing newline. Commas, brackets, and other characters are not allowed in the output." I'll allow returning the string instead of printing it though. – Calvin's Hobbies – 2016-01-13T22:20:11.887
Why are you dividing by
(5*4*3*2*1)
? That part makes no sense... Why take it out? It should be 1 in 35,064,160,560 ((69*68*67*66*65) x (26)
) – Canadian Luke – 2016-01-14T00:06:37.5031@CanadianLuke The order of the first 5 numbers does not matter. There are
5! = 5*4*3*2*1
ways to arrange 5 things, so you factor that out. – Calvin's Hobbies – 2016-01-14T00:09:30.393Ahhh I understand now. I was thinking of the formula for being in order – Canadian Luke – 2016-01-14T00:13:01.447
@Calvin'sHobbies, is
ans = OK
in MATLAB? You said program or function, and by defaultans =
is accepted for functions but your wording makes me wonder. – Stewie Griffin – 2016-01-29T11:41:34.403@StewieGriffin That's ok – Calvin's Hobbies – 2016-01-29T20:56:53.763