BBC BASIC
« Lottery numbers & non repeating values tool »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Lottery numbers & non repeating values tool  (Read 1137 times)
MarsFS
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 16
smiley Re: Lottery numbers & non repeating values tool
« Reply #8 on: Sep 1st, 2017, 10:20pm »

Here's another version using a knuth shuffle with multiple lines and sorted and formatted output:
Code:
      REM Lotto number generator      max%=49      nums%=7      DIM allNumbers(max%)      DIM sorted(max%)      REM Creat a fresh set of numbers      FOR T%=1 TO max%        allNumbers(T%)=T%      NEXT      REPEAT        PROC_newnumbers        key$ =GET$      UNTIL key$="q" OR key$="Q"      PRINT "Done"      END      DEF PROC_newnumbers      LOCAL T%,N%,C%,J%,A$      CLS      PRINT "Lotto Number Picker"      PRINT "-------------------"      INPUT "How many lines (1-18): ", J%      IF J%<2 OR J%>18 THEN        J%=1        A$="is 1 line"      ELSE        A$="are "+STR$(J%)+" lines"      ENDIF      CLS      PRINT "Here ";A$;" of ";STR$(nums%);" numbers for Lotto Max:": PRINT      FOR C%=1 TO J%        REM randomly shuffle the numbers        FOR T% = max% TO 2 STEP -1          SWAP allNumbers(T%),allNumbers(RND(T%))          sorted(T%)=0        NEXT        sorted(1)=0        REM choose a random set and sort        N%=RND(max%-nums%+1)        FOR T%=N% TO N%+nums%-1          sorted(allNumbers(T%))=allNumbers(T%)        NEXT        REM print sorted list        PRINT "Line ";RIGHT$("0"+STR$(C%),2);":   ";        FOR T%=1 TO max%          IF sorted(T%) PRINT RIGHT$(" "+STR$(sorted(T%)),2);"  ";        NEXT        PRINT      NEXT      PRINT:PRINT "Press any key for more numbers, Press 'Q' to quit"      ENDPROC 

User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
smiley Re: Lottery numbers & non repeating values tool
« Reply #9 on: Sep 2nd, 2017, 11:15am »

on Sep 1st, 2017, 10:20pm, MarsFS wrote:
Here's another version using a knuth shuffle with multiple lines and sorted and formatted output

Nice, and works without modification on both BB4W and BBCSDL!

For my own interest I ran some tests on how many calls to RND(52) might be necessary before a specific unique number is returned. The answer seemed to be that needing to call it more than 900 times is not that unlikely (the highest I saw was 996)! Obviously typically it will be fewer, but it illustrates the uncertainty in execution time that can arise from using that technique.

Richard.
User IP Logged

Leo
New Member
Image


member is offline

Avatar




PM


Posts: 10
smiley Re: Lottery numbers & non repeating values tool
« Reply #10 on: Sep 2nd, 2017, 4:00pm »

Although I can't disagree with the logic behind "run time is unpredictable" - the lottery case here is a complete frippery. It's just a "throwaway" toy.
Of course I wouldn't use the technique I did for anything approaching any seriousness but I stand by my choice for the lottery case because..

a) It's a complete frippery.
b) The program is very short.
c) We're only selecting ANY 7 numbers from 49 so there's no chance of this taking forever.
d) The quality of the random numbers is irrelevant because any 7 will have an equal chance of winning.

I also ran some trials (a lot).
The maximum number of lookup clashes in any single line was 6 - sounds a lot.
However, in creating 10000 lottery lines a repeat lookup was necessary in 6.7% of cases - no problem.

Henceforward I will use the dates of my children's birthdays to derive (winning) lottery lines. grin
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
smiley Re: Lottery numbers & non repeating values tool
« Reply #11 on: Sep 2nd, 2017, 4:43pm »

on Sep 2nd, 2017, 4:00pm, Leo wrote:
I stand by my choice for the lottery case because...

That's fine, with those qualifications. The trouble is that people may adapt the code for other applications without appreciating its limitations (for example they may come upon it years later as the result of a search).

My experience is that there is widespread misunderstanding about pseudo-random numbers and statistics, and although it's unlikely that anybody would use BBC BASIC for an online casino program, or something like that, it's not impossible.

Several years ago I wrote this article at the Wiki to draw attention to some of the pitfalls. It includes simple lottery draw and card shuffling programs. It's out of date to the extent that BBC BASIC no longer uses the value of TIME as a seed.

Richard.
« Last Edit: Sep 2nd, 2017, 4:52pm by Richard Russell » User IP Logged

Leo
New Member
Image


member is offline

Avatar




PM


Posts: 10
smiley Re: Lottery numbers & non repeating values tool
« Reply #12 on: Sep 2nd, 2017, 9:00pm »

Thanks for that link Richard - very good article.
Although I'm gradually working my way through the info in the wiki, I admit I haven't read that one before. Everybody who uses BB4W should go and rummage through the wiki - there's so much excellent information in there.

I use CryptGenrandom a lot for 'professional' use. I think I posted something here that used it a short time ago - but I don't remember what right now. (My memory ain't what it used to be).

Thanks again for the info.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls