I'm making a "guess that tune" game in Visual Basic 6 that is supposed to play each song in a random order:
' from frmGuessGame.frm Private Sub Swap(ByRef Value1 As Variant, ByRef Value2 As Variant) Dim Temporary As Variant Temporary = Value1 Value1 = Value2 Value2 = Temporary End Sub Private Sub ShuffleList() Dim LoopCtr As Integer, SwapWith As Integer For LoopCtr = LBound(InnerPlaylist) To UBound(InnerPlaylist) SwapWith = (Rnd * (UBound(InnerPlaylist) - LBound(InnerPlaylist))) + LBound(InnerPlaylist) Swap InnerPlaylist(LoopCtr), InnerPlaylist(SwapWith) Next End Sub
My initialization function does include the
Randomize statement, so it should be a good, even shuffle.
' from mdiMain.frm Private Sub MDIForm_Load() 'initialize pseudo-random number generator Randomize frmMusiguess.Show frmSplash.Show End Sub
I'm not sure, however, that this is the best way to do it. Am I on the right track?