You mentioned in one of your posts in one of your thread that would like to resume a session from a fixed starting point the Rnd value list.
I created a small sample which is capable of doing this:
Code in a module:
To test in a Form with 2 command buttons:Code:Option Explicit Private m_lCalls As Long Private m_lSeed As Long Public Sub RNDInit(ByVal lSeed As Long) m_lCalls = 0 m_lSeed = lSeed If m_lSeed = 0 Then m_lSeed = 100 * Timer Rnd -1 Randomize Abs(m_lSeed) End Sub ' generates a random value between min and max Public Function RNDVal(ByVal lMin As Long, ByVal lMax As Long, Optional ByVal lIteration As Long = -1) As Long Dim i As Long If lIteration <> -1 Then RNDInit m_lSeed For i = 1 To lIteration - 1: Rnd: Next m_lCalls = lIteration - 1 End If RNDVal = Int((lMax - lMin + 1) * Rnd + lMin) m_lCalls = m_lCalls + 1 End Function
Code:Option Explicit Private Sub Form_Load() RNDInit 12345 End Sub Private Sub Command1_Click() Debug.Print RNDVal(0, 255) End Sub Private Sub Command2_Click() Debug.Print "Item 4", RNDVal(0, 255, 4) End Sub




Reply With Quote