How to generate Lottery Numbers on the Commodore 64

- by

In 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.

Here’s the lottery generator code:

10 x=rnd(-ti)
20 for i=1 to 6
30 rn=int(rnd(1)*49)+1
40 for j=1 to i
50 if n(j)=rn then 30
60 next j
70 n(i)=rn
80 next i
100 print
110 for i=1 to 6
120 print n(i);
130 next
140 print
199 end

To 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).

Any questions, please let me know below.

Happy retro hacking!

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

1 thought on “How to generate Lottery Numbers on the Commodore 64”

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.