Author |
Topic: re RND (Read 780 times) |
|
leslie griffin
Guest
|
 |
re RND
« Thread started on: Apr 1st, 2010, 11:20pm » |
|
Updated my prog with the bugfree lotto generator RND. I think anyone can run it now. something is wrong if i choose numbers less than 43 it seems to give to high a payout. if i choose numbers in the 40s it pays far lower than it should. it was showing approx 22% with my original but longwinded RND generator and error check mode 20 dim ltt%(49) dim lot(10,6) dim drww(7) dim hit(10) dim ttal(10,7) dim mwon(10) gh=1 ttdr=1 for f=1 to10 mwon(f)=1 for g= 1 to 6 lot(f,g)=0 next next proc_setup proc_choose6 off repeat proc_draw proc_logic proc_scrn ttdr=ttdr+1 until gh=2 end defproc_setup cls print tab(0,6)"This is a lottery simulator" input tab(0,15)"how mamy tickets do you want Max=10 " ticket print tab(0,8)"now choose 6 different numbers between 1 and 49 for each ticket press enter after each entry " print tab(0,9)"3 numbers pays 10" print tab(0,10)"4 numbers pays 50" print tab(0,11)"5 numbers pays 1000" print tab(0,12)" 5 numbers plus the bonus ball pays 100000" print tab(0,13)"6 numbers pays 3 million" endproc defproc_choose6 for d=1 to ticket for t=1 to 6 repeat input tab(t*4,16+d) lot(d,t) until (lot(d,t)>0 and lot(d,t)<50) next next endproc defproc_draw max% = 49 num% = 7 for I% = 1 to max% ltt%(I%) = I% next I% for choice% = 1 to num% R% = rnd(max%) drww(choice%)=R% ltt%(R%) = ltt%(max%) max% = max%-1 next choice% endproc defproc_logic for z=1 to ticket hit=0 for n=1 to 6 for m=1 to 6 if lot(z,m) = drww(n) then hit = hit+1 next next if hit=1 then ttal(z,1)=ttal(z,1)+1 if hit=2 then ttal(z,2)=ttal(z,2)+1 if hit=3 then ttal(z,3)=ttal(z,3)+1 mwon(z)=mwon(z)+10 if hit=4 then ttal(z,4)=ttal(z,4)+1 mwon(z)=mwon(z)+50 sound 3,-15,96,1 if hit=5 then ttal(z,5)=ttal(z,5)+1 mwon(z)=mwon(z)+1000 proc_bonusball if hit=6 then ttal(z,6)=ttal(z,6)+1 mwon(z)=mwon(z)+3000000 if hit=7 then ttal(z,7)=ttal(z,7)+1 mwon(z)=mwon(z)+100000 next endproc defproc_bonusball for s=1 to 6 if drww(7)=lot(z,s) then hit=7 next endproc defproc_scrn print tab(12,0)"draw number 3 HIT 4 HIT 5 HIT 6 HIT 5 + BONUS MONEY WON RATIO" for s= 1 to ticket print tab(6,1+s) ttdr ttal(s,3) ttal(s,4) ttal(s,5) ttal(s,6)" " ttal(s,7)" " mwon(s)" "int(mwon(s)/ttdr*100)"%" print tab(0,15)"number of years running is " int(ttdr/52) next endproc
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: re RND
« Reply #1 on: Apr 2nd, 2010, 10:13am » |
|
on Apr 1st, 2010, 11:20pm, Guest-leslie griffin wrote:something is wrong. if i choose numbers less than 43 it seems to give to high a payout. if i choose numbers in the 40s it pays far lower than it should. |
|
I don't know how important this is, but in the case of 'five balls plus bonus ball' the payout is 101000 (not 100000) because you've added the normal '5 ball' payout as well.
BBC BASIC's RND is quite a good generator, considering its relatively short sequence length (2^33-1), because it uses a Linear Feedback Shift Register having desirable characteristics as a Pseudo Random Number Generator.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: re RND
« Reply #2 on: Apr 2nd, 2010, 10:55am » |
|
on Apr 1st, 2010, 11:20pm, Guest-leslie griffin wrote:it was showing approx 22% with my original but longwinded RND generator and error check |
|
22% is far too low a result, but whether that is because your original RND was untrustworthy or because you didn't run enough trials I don't know.
You would have to run your program for an infeasibly long time to get meaningful statistics. For example the chances of winning the top prize (6 numbers) are about 1 in 14 million; so to measure an average percentage payout figure that you can trust you'd have to run something like a billion trials!
If you disable the 100000 and 3000000 prizes, it's only necessary to run the program for about 500000 trials (!) to give reasonably reliable statistics. If I do that I get around a 60% average payout irrespective of the numbers I choose. I don't see any evidence of bias.
Unless you're a mathematician, working with 'random' numbers is beset with pitfalls. You must at the very least have an understanding of how many trials you need to carry out before the results have statistical significance.
Richard.
|
|
Logged
|
|
|
|
|