Biased random?

Mark Dickinson dickinsm at gmail.com
Thu Aug 30 16:55:53 EDT 2007


> One possible fix:  do
>
>   x = randint(0, 10) - randint(0, 10)
>   x = abs(x) - (x<0)
>
> This collapses -1 and 0 to 0, -2 and 1 to 1, etc.

Or a slightly simpler formula that ends up producing the same
distribution:

x = min(randint(0, 10), randint(0, 10))

Mark




More information about the Python-list mailing list