I thought I would write a lottery number generator since I have not had any luck winning the big jackpot - http://megamillions.com/. So far, after over 1.2 million tries, I still have not hit all the numbers from yesterday: 2, 17, 22, 32, 51, 35 (last one is the mega ball). Fun little project that and I thought others would be interested. Let me know if you have a cleaner implementation in mind. --- code: def giveMeNumbers @a=[] while @a.length <=4 @a << rand(56)+1 @a.uniq! end @mega = rand(46)+1 @outPut = @a.sort.push(@mega).join('', '') end 100000.times do puts giveMeNumbers end --- Sunny ps. The next step is to calculate what my winnings would be based on the payout table - for non-jackpot winners. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I estimate you need to run this at least 550,731,822 times in order to get the same numbers twice. ----- Ryan Bigg Freelancer http://frozenplague.net On 04/12/2008, at 2:43 PM, Sunny Beach wrote:> I thought I would write a lottery number generator since I have not > had any luck winning the big jackpot - http://megamillions.com/. So > far, after over 1.2 million tries, I still have not hit all the > numbers from yesterday: 2, 17, 22, 32, 51, 35 (last one is the mega > ball). > > Fun little project that and I thought others would be interested. > Let me know if you have a cleaner implementation in mind. > > --- code: > > def giveMeNumbers > @a=[] > > while @a.length <=4 > @a << rand(56)+1 > @a.uniq! > end > > @mega = rand(46)+1 > @outPut = @a.sort.push(@mega).join('', '') > > end > > 100000.times do > puts giveMeNumbers > end > > --- > > Sunny > > ps. The next step is to calculate what my winnings would be based > on the payout table - for non-jackpot winners. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 4, 2008, at 1:55 AM, Ryan Bigg wrote:> I estimate you need to run this at least 550,731,822 times in order > to get the same numbers twice. > ----- > Ryan Bigg > Freelancer > http://frozenplague.net > > On 04/12/2008, at 2:43 PM, Sunny Beach wrote: > >> I thought I would write a lottery number generator since I have not >> had any luck winning the big jackpot - http://megamillions.com/. So >> far, after over 1.2 million tries, I still have not hit all the >> numbers from yesterday: 2, 17, 22, 32, 51, 35 (last one is the mega >> ball). >> >> Fun little project that and I thought others would be interested. >> Let me know if you have a cleaner implementation in mind. >> >> --- code: >> >> def giveMeNumbers >> @a=[] >> >> while @a.length <=4 >> @a << rand(56)+1 >> @a.uniq! >> end >> >> @mega = rand(46)+1 >> @outPut = @a.sort.push(@mega).join('', '') >> >> end >> >> 100000.times do >> puts giveMeNumbers >> end >> >> --- >> >> Sunny >> >> ps. The next step is to calculate what my winnings would be based >> on the payout table - for non-jackpot winners.class MegaMillions # From a set of integers from 1 to *numbers*, choose *count*, # plus a single bonus number from 1 to *bonus* def initialize(numbers=56, count=5, bonus=46) @numbers, @count, @bonus = numbers, count, bonus @balls = (1..@numbers).to_a @pick = nil end def autopick @pick = [] @pick << @balls.sort_by{rand}.first(@count).sort @pick << rand(@bonus)+1 self end def to_s autopick unless @pick "#{@pick.first.join('', '')} #{@pick.last}" end def inspect "\#<#{self.class.name}:#{''%#x''%self.object_id} #{@numbers}C#{@count} + #{@bonus}#{%{ => #{to_s}} if @pick}>" end end picker = MegaMillions.new puts picker.autopick -Rob P.S. I think the sweet spot on the payout matrix is to keep the dollar in your pocket ;-) Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---