ChatGPT Lotto Program

Author Message
Glen0
Regular Member

Joined: 12/10/2014
Location: New Zealand
Posts: 82
 Posted: 11:34pm 25 Feb 2023

Typed the following question into ChatGPT:

"write a program in mmbasic to create an array with integers 1 to 40 and then to select six of them, removing them from the array when they are selected, then print the six numbers"
============================================================================
REM Create an array with integers 1 to 40
DIM nums(40)
FOR i = 1 TO 40
nums(i) = i
NEXT

REM Select six numbers
DIM selected(6)
FOR i = 1 TO 6
REM Pick a random index from the remaining numbers
index = INT(RND * (40 - i + 1)) + i - 1

REM Add the selected number to the output array
selected(i) = nums(index)

REM Remove the selected number from the input array
FOR j = index TO 39
nums(j) = nums(j + 1)
NEXT
NEXT

REM Print the selected numbers
PRINT "Selected numbers:"
FOR i = 1 TO 6
PRINT selected(i)
NEXT

This program first creates an array called nums with integers 1 to 40 using a FOR loop. Then, it selects six random numbers from the nums array by repeatedly picking a random index from the remaining numbers, adding the selected number to the selected array, and removing the selected number from the nums array using another FOR loop.

Finally, the program prints the selected numbers using another FOR loop and a PRINT statement.
============================================================

These are the results I got.
AUTOSAVE

Saved 586 bytes
>
Time taken: 1765mS
RUN
Selected numbers:
27
20
25
24
17
14
>

Feel free to use these numbers next week.