Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random numbers
#5
The entire program basically consists of just one procedur, which only makes sense for an AI.  Rolleyes

Without a procedur, and with a query about how many numbers should be drawn.

Code: (Select All)

'Zufallsgenerator - 7. Nov. 2024

Option _Explicit

' Seed the random number generator
Randomize Timer

Dim As Integer anzahlNummern
Dim As Integer count
Dim As Integer newNumber
Dim As Integer isDuplicate

Print
Input "Anzahl der Zufallsnummern (Max 10): ", anzahlNummern
If anzahlNummern > 10 Then
  Beep: Print "Maximal 10 Nummern!"
  Sleep 2
  System
End If

Dim As Integer numbers(anzahlNummern)

count = 0
Dim As Integer i
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 = anzahlNummern

' Print the selected numbers
Print Using "The ## unique numbers are:"; anzahlNummern
For i = 1 To anzahlNummern
  Print numbers(i)
Next i

End
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: 1 Guest(s)