[ create a new paste ] login | about

Link: http://codepad.org/e6z8PyTb    [ raw code | output | fork ]

Python, pasted on Feb 22:
1
2
3
4
5
6
7
8
9
10
11
12
def randInt(max, r):
    while True:
        base = 0
        val = 0
        while base < max:
            base = base * 2
            val = val * 2 + r()
        if val < max:
            return val
import random

print randInt(5, lambda: random.random()>=0.5)


Output:
1
Timeout


Create a new paste based on this one


Comments: