How to generate Lottery Numbers on the Commodore 64

Published: March 31, 2018, 4:39 p.m.

b'
\\nIn this episode I’ll demonstrate how to draw random lottery numbers on a Commodore 64. The secret sauce here is not only the RND function to generate random numbers, but also two loops inside each other that prevent the same number from coming up more than once.
\\nHere’s the lottery generator code:
\\n10 x=rnd(-ti)
\\n20 for i=1 to 6
\\n30 rn=int(rnd(1)*49)+1
\\n40 for j=1 to i
\\n50 if n(j)=rn then 30
\\n60 next j
\\n70 n(i)=rn
\\n80 next i
\\n100 print
\\n110 for i=1 to 6
\\n120 print n(i);
\\n130 next
\\n140 print
\\n199 end
\\nTo adapt this listing to match your local lottery, change line 20 to the amount of numbers to be drawn from your pool (6 in my example), and change the value in line 30 to match the size of your pool (49 in my example).
\\nAny questions, please let me know below.
\\nHappy retro hacking!
'