Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Seeding Values

Status
Not open for further replies.

MrMoocow

Programmer
May 19, 2001
380
US
I'm not sure if the subject is correct. But I need to radomly create a delimated (sp?) random list of numbers.
Example 1 threw 6 might return

3,4,6,2,1,5 or 1,2,3,4,6,5

Any ideas?
Brad,
Free mp3 player,games and more.
 
Somewhat crude, but for small values of the integer and 'light weight' usage:

Code:
 Public Function basShuffleN(intNum As Integer) As String
 
    Dim PlaceArray() As Single
    Dim Idx As Integer
    Dim sngTemp1 As Single
    Dim sngTemp2 As Single
    Dim Sorted As Boolean
    Dim strTemp As String

    ReDim PlaceArray(intNum, 2)

    'Create an array with the Integers and a Random Number
    For Idx = 1 To UBound(MyArray)
        PlaceArray(Idx, 1) = Idx
        PlaceArray(Idx, 2) = Rnd()
    Next Idx

    'Sort acording to the Random Number
    Do While Not Sorted
        Sorted = True
        For Idx = 1 To UBound(PlaceArray) - 1
            If (PlaceArray(Idx, 2) > PlaceArray(Idx + 1, 2)) Then
                'Swap
                Sorted = False
                sngTemp1 = PlaceArray(Idx, 1)
                sngTemp2 = PlaceArray(Idx, 2)
                PlaceArray(Idx, 1) = PlaceArray(Idx + 1, 1)
                PlaceArray(Idx, 2) = PlaceArray(Idx + 1, 2)
                PlaceArray(Idx + 1, 1) = sngTemp1
                PlaceArray(Idx + 1, 2) = sngTemp2
            End If
        Next Idx
    Loop

    'Collect the 'Randomized" Integers into a String
    For Idx = 1 To UBound(PlaceArray, 1)
        strTemp = strTemp & PlaceArray(Idx, 1)
        If (Idx < UBound(PlaceArray, 1)) Then
            strTemp = strTemp & &quot;,&quot;
        End If
    Next Idx

    'Return the delimited String
    basShuffleN = strTemp

End Function

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top