Why PEEK and POKE for random numbers?
It's a very obfuscating way to simply make certain that the values don't appear twice in the same drawing. After looking over the original code, I went in and made what I thought was some simple Steve Edits(tm) to bring the code up to more modern programming practices:
REM A Powerball drawing program by Martin VandenHurk.
REM Which Steve finds
to be a very goofy way
to do Powerball numbers...
REM So this
is the modified version
, which doesn
't use GOTO, or obsolete PEEK and POKE commands.
'FOR l = 1 TO 59
'POKE 5000 + l, l
'NEXT
b$ = "11111111111111111111111111111111111111111111111111111111111" 'Steve addition of a 59 length string of all 1's.
'SLEEP 3 'Why a sleep statement here? If we're going to time program execution, we don't need it to slow things down
'FOR l = 1 TO 59 'For that much, why are we even bothering with these PRINT statements at all? The CLS below erases them from the screen too fast for us to even register them with our human eyesight...
' PRINT PEEK(5000 + l);
' PRINT l; 'Even if we do print our values to the screen, WTH do we need to PEEK the numbers from 1 to 59? We just put them in memory with POKE in perfect order. Why not just print them and be done with it?
'NEXT
'PRINT "Now drawing powerball numbers..."
'ct = 1
'here:
FOR ct
= 1 TO 6 ' We want 6 numbers , so a FOR loop makes sense here, rather than a GOTO label DO ' A simple DO loop, to get an unique X. If we draw the same number twice, simply redraw until it's not an used number 'IF PEEK(5000 + x) <> 0 THEN r(ct) = x: POKE 5000 + x, 0: GOTO there
'GOTO here
r
(ct
) = x:
MID$(b$
, x
, 1) = "0" ' Basically the same as the code after the THEN which I commented out above, but using a simple string rather than PEEK and POKE to check for used numbers.'there: ' All needlessly complicated GOTO labels and junk, which simply obfuscates the code. These were all commented out and removed by Steve
' ct = ct + 1
' IF ct = 6 THEN GOTO done ELSE GOTO here
' done:
'CLS ' No need for a CLS here, or else there's no need for the printing above, as it'll simply dash off the screen too quick to read.
PRINT "Here are your 5 Powerball numbers:" PRINT "The red Powerball number is:";
PRINT "time started : "; a$
And, to compare the two, without all the comments in the way, here's the original again:
REM A Powerball drawing program by Martin VandenHurk.
PRINT "Now drawing powerball numbers..." ct = 1
here:
there:
ct = ct + 1
done:
PRINT "Here are your 5 Powerball numbers:" PRINT "The red Powerball number is:";
PRINT "time started : "; a$
And here's the altered version, without the extra junk left in it:
REM A Powerball drawing program by Steve.
b$ = "11111111111111111111111111111111111111111111111111111111111"
r
(ct
) = x:
MID$(b$
, x
, 1) = "0"PRINT "Here are your 5 Powerball numbers:" PRINT "The red Powerball number is:";
PRINT "time started : "; a$
From a 34 line program with PEEKs and POKEs, labels and GOTOs, to a simple little 21 line program. This goes from something which has new (or modern) coders scratching their heads and saying, "What the heck does this do?", (such as in the original post), to becoming something simple enough for anyone to basically glance at and figure out what we're doing.
A lot of these old commands are in the language just for backwards compatibility reasons. They're not something which a respectable, decent modern-day programmer needs in their toolbox. PEEK and POKE are two commands best simply forgotten about, unless you're having to maintain/convert legacy code from the 90's. And GOTO.... GOTO is still a need tool for the modern programmer, but it shouldn't be the first tool of choice, when simple FOR-NEXT, DO-LOOP, and WHILE-WEND statements can replace it easily in most cases and make the code much more readable and easier to figure out.