title image


Smiley Re: Randomize ohne Duplikate


Public Function Ziehung(A() As Long, Untergrenze As Long, Obergrenze As Long)

Dim I As Long, J As Long, K As Long, OK As Boolean

If Obergrenze - Untergrenze < UBound(A) - LBound(A) Then

MsgBox "Wertebereich zu klein!", vbCritical

Else

Randomize

For I = LBound(A) To UBound(A)

A(I) = Untergrenze - 1

Next I

For I = LBound(A) To UBound(A)

Do

OK = True

K = Int((Obergrenze - Untergrenze + 1) * Rnd + Untergrenze)

For J = LBound(A) To I - 1

If K = A(J) Then

OK = False

Exit For

End If

Next J

Loop Until OK

A(I) = K

Next I

End If

End Function



Public Function TesteZiehung()

Dim I As Long, Werte(1 To 50) As Long

Ziehung Werte, 1, 100

For I = LBound(Werte) To UBound(Werte)

Debug.Print I, Werte(I)

Next I

End Function





Gruß aus dem Norden
Reinhard


Bitte immer die Access-Version angeben!
DB-Wiki


Wie man Fragen richtig stellt

YaccessAccess-FAQUnd ansonsten: Wikipedia




geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: