random.sample with large weighted sample-sets?

Charles Allen ca137tmp at earthlink.net
Sun Feb 16 17:35:58 CET 2014


How efficient does this thing need to be?

You can always just turn it into a two-dimensional sampling problem by
thinking of the data as a function f(x=item), generating a random x=xr
in [0,x], then generating a random y in [0,max(f(x))].  The xr is
accepted if 0 < y <= max(f(xr)), or rejected (and another attempt made) if
y > max(f(xr)).



More information about the Python-list mailing list