roulette simulator

jammoca

Banned
Joined
Nov 6, 2002
Messages
1,100
I would like to have a list of student names, and a command button, that when pressed, begins highlighting the names one at a time ( starting at the top, moving down through the list, then starting at the top again, moving down through the list again, etc etc) each time the time that each name is highlighted gets longer and longer, effectively like a roulette wheel.

Eventually, one of the names would remain highlighted.

When the command button is pressed again, the 'roulette' highlighting process starts again, and eventually another name would be highlighted.

Is this possible ?

I already have a 'random student selector' program operating that returns a student name randomly and without ever returning a name twice, but it lacks the drama and suspense this 'roulette' method might provide.
 
Very good modifications. Brain definitely missed out on some of the obvious problems in my code. Thank you.

What's really needed is a slowdown code which won't just be linear. Perhaps replacing:
Code:
 Sleep intSlowDown * 10
with
Code:
Sleep Log(intSlowDown)*50
would be more appropriate? Or something even more mathematical, like a binomial distribution so that it really slows down toward the end?

Right now, it is totally random, but doesn't hold the suspense as much due to the fact that it can end after a single rotation (when it's still moving fast). Ideally it would slow down more depending on how close it was to the target.
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Cumulative Binomial Distribution in reverse would be ideal. If you normalize it to have the last roulette spin take a second, then you'd have a wonderful end ramp-up to the selection as almost all moves would take (nearly) a second. Normalize to any other amount if you'd prefer (half a second, etc.) if a second is too long. You can use the BINOMDIST() function to do it, but I'm having a bit of trouble with the math.
 
Upvote 0
This adds a better algorithm for waiting (still linear, but slightly better), and gives a 30% chance that it will hop back a space on chosing the person (for added suspense):
Code:
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub Roulette()
    Dim i, j As Integer
    Dim intSlowDown As Integer
    Dim intStudents As Integer
    Dim intRotations As Integer
    Dim intStopsOn As Integer
    Dim intTotal As Integer
    
    intStudents = Range("A1").End(xlDown).Row
    
    intRotations = Int((5 * Rnd) + 3)
    intStopsOn = Int((intStudents * Rnd) + 1)
    intTotal = intRotations * intStudents + intTotal
        
    Range("A1:A" & intStudents).Interior.ColorIndex = xlNone
    For j = 1 To intRotations
        For i = 1 To intStudents
            intSlowDown = intSlowDown + 1
            Cells(i, 1).Interior.ColorIndex = 6
            If i = 1 Then
                Cells(intStudents, 1).Interior.ColorIndex = xlNone
            Else
                Cells(i - 1, 1).Interior.ColorIndex = xlNone
            End If
            
            If j = intRotations And i = intStopsOn Then
                If Rnd >= 0.3 Then
                    Sleep 1000
                    Cells(i, 1).Interior.ColorIndex = xlNone
                    If i = 1 Then
                        Cells(intStudents, 1).Interior.ColorIndex = 6
                        MsgBox (Cells(intStudents, 1).Value & " has been chosen")
                    Else
                        Cells(i - 1, 1).Interior.ColorIndex = 6
                        MsgBox (Cells(i - 1, 1).Value & " has been chosen")
                    End If
                    Exit Sub
                Else
                    MsgBox (Cells(i, 1).Value & " has been chosen")
                End If
                Exit Sub
            End If
            
            Debug.Print (j * 1000) / intRotations + (i * 100) / intStudents
            Sleep (j * 500) / intRotations + (i * 50) / intStudents
        Next i
    Next j
    
End Sub
 
Upvote 0
i haven't tried any of that code yet, but doesn't rnd repeat itself every time ?

aren't you supposed to seed it with a different value each time so the results are different ?
 
Upvote 0

Forum statistics

Threads
1,215,949
Messages
6,127,892
Members
449,411
Latest member
AppellatePerson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top