Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random numbers
#1
Hello

can someone tell me why this little program will not work i dont really understand why.

badger

thanks in advance

Code: (Select All)
DECLARE SUB GenerateUniqueNumbers()

DIM numbers(5) AS INTEGER
DIM count AS INTEGER
DIM i AS INTEGER
DIM newNumber AS INTEGER
DIM isDuplicate AS INTEGER

SUB GenerateUniqueNumbers
    count = 0
    DO
        ' Generate a random number between -1 and 71
        newNumber = INT(RND * 73) - 1
        isDuplicate = 0

        ' Check if the number is already in the array
        FOR i = 1 TO count
            IF numbers(i) = newNumber THEN
                isDuplicate = 1
                EXIT FOR
            END IF
        NEXT i

        ' If it's not a duplicate, add it to the array
        IF isDuplicate = 0 THEN
            count = count + 1
            numbers(count) = newNumber
        END IF
    LOOP UNTIL count = 5

    ' Print the selected numbers
    PRINT "The 5 unique numbers are:"
    FOR i = 1 TO 5
        PRINT numbers(i)
    NEXT i
END SUB

' Seed the random number generator
RANDOMIZE TIMER

' Call the subroutine to generate and display the numbers
GenerateUniqueNumbers
Reply


Messages In This Thread
random numbers - by badger - 11-06-2024, 11:15 PM
RE: random numbers - by Dav - 11-06-2024, 11:30 PM
RE: random numbers - by badger - 11-06-2024, 11:42 PM
RE: random numbers - by Dav - 11-06-2024, 11:51 PM
RE: random numbers - by Kernelpanic - 11-07-2024, 05:24 PM
RE: random numbers - by bplus - 11-07-2024, 05:52 PM
RE: random numbers - by bplus - 11-07-2024, 07:03 PM
RE: random numbers - by bplus - 11-07-2024, 07:10 PM
RE: random numbers - by DANILIN - 11-08-2024, 02:22 AM



Users browsing this thread: 2 Guest(s)