Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programming Interview Questions

Name: Anonymous 2011-05-22 16:08

You have a stream of numbers that you can see one at a time. With uniform probability, select only one of these numbers. That is, each number in the stream has the same probability of being selected. You cannot just store the entire stream to an array or read through the stream twice.

Name: Anonymous 2011-05-22 17:03

>>12
Just tested it quickly:


Private Sub Form_Load()
    Dim k(100) As Integer
    For j = 1 To 10000
    o = 0
    For i = 1 To 100
        If Rnd < 1 / i Then o = i
    Next i
    k(o) = k(o) + 1
    Next j
   
    For j = 1 To 100
        Me.Line (j, 100)-(j, 100 - k(j)), 0
    Next j
End Sub


Yes, VB6 is an embarrassment, but it works and produces an even distribution reliably. So EAT IT.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List