Weibull distr. random number generation

Mark Dickinson dickinsm at gmail.com
Sat Nov 20 12:09:33 EST 2010


On Nov 19, 3:21 pm, Dimos <dimos_anastas... at yahoo.com> wrote:
> I would like to use the random module, and if I understand well the Random class, to create  1300 decimal numbers in python, by providing the 2 Weibull parameters (b,c). How this can be done???
>
> import random
> print random
> random.weibullvariate(b,c)
> How can I set the population size n=1300 in decimals?

random.weibullvariate(b, c) generates a single sample from the
specified Weibull distribution.  If you want 1300 samples, you'd use
this within a loop.  For example, here's code to put 10 Weibull
variates with scale parameter 12345.0 and shape parameter 6.0 into a
list:

>>> import random
>>> samples = []
>>> for i in xrange(10):
...     samples.append(random.weibullvariate(12345.0, 6.0))
...
>>> print samples
[15553.186762792948, 14304.175032317309, 9015.5053691933044,
12585.469181732506, 9436.2677219460638, 13350.89758791281,
5687.4330250037565, 12172.747202474553, 9687.8685933610814,
11699.040541029028]

A more experienced Python programmer might use a list comprehension to
achieve the same effect in a single line:

>>> samples = [random.weibullvariate(12345.0, 6.0) for _ in xrange(10)]
>>> print samples
[10355.396846416865, 14689.507803932587, 11491.850991569485,
14128.56397290655, 12592.739991974759, 9076.7752548878998,
11868.012238422616, 12016.784656753523, 14724.818462506191,
13253.477389116439]

Is this the sort of thing you were looking for?

--
Mark



More information about the Python-list mailing list