Gerhard Fiedler wrote: > On 2006-07-23 17:12:20, [EMAIL PROTECTED] wrote: > >> I am a newbie to Python and would like to genereate some numbers >> according to geometric distribution. However, the Python Random package >> seems do not have implemented functionality. I am wondering is there >> exist any other libraries that can do this job? > > The usual way is to generate standard random numbers (linear distribution) > and then apply whatever transformation you need to generate the desired > distribution.
That only works if there is such a transformation. The geometric distribution and many others have been implemented in numpy: http://www.scipy.org/NumPy In [1]: from numpy import random In [2]: random.geometric(0.5, size=100) Out[2]: array([1, 5, 2, 3, 1, 1, 2, 3, 1, 1, 2, 1, 1, 1, 2, 2, 3, 3, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 3, 1, 1, 3, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 3, 1, 4, 1, 1, 1, 2, 1, 2, 3, 2, 1, 1, 1, 1, 1, 3, 1, 1, 2, 6, 1, 1, 3, 2, 1, 1, 2, 1, 1, 7, 2, 1, 1, 2, 1, 1, 2, 4, 1, 2, 1, 4, 2, 1, 1, 2, 1, 4, 2, 1, 1, 3, 1, 3, 1]) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list