@databench.on
def run(self):
    'Run when button is pressed.'
    inside = 0
    for draws in range(1, self.data['samples']):
        r1 = random.random()
        r2 = random.random()
        if (((r1 ** 2) + (r2 ** 2)) < 1.0):
            inside += 1
        if ((draws % 1000) != 0):
            continue
        (yield self.emit('log', {'draws': draws, 'inside': inside}))
        p = (inside / draws)
        pi = {'estimate': (4.0 * p), 'uncertainty': ((4.0 * math.sqrt(((draws * p) * (1.0 - p)))) / draws)}
        (yield self.set_state(pi=pi))
    (yield self.emit('log', {'action': 'done'}))
Run when button is pressed.
@databench.on
def run(self):
    
    inside = 0
    for draws in range(1, self.data['samples']):
        r1 = random.random()
        r2 = random.random()
        if (((r1 ** 2) + (r2 ** 2)) < 1.0):
            inside += 1
        if ((draws % 1000) != 0):
            continue
        (yield self.emit('log', {'draws': draws, 'inside': inside}))
        p = (inside / draws)
        pi = {'estimate': (4.0 * p), 'uncertainty': ((4.0 * math.sqrt(((draws * p) * (1.0 - p)))) / draws)}
        (yield self.set_state(pi=pi))
    (yield self.emit('log', {'action': 'done'}))