I would like to generate a random integer according to the binomial distribution. That is, I would like to generate a Bin(n,p) random value. That's number between 0 and n in which the probability we get the value k is
Here is an inefficient method (which requires n calls to
Is there a better way to do this (already built into Sage, I hope)?
(In Matlab, this can be done via the
asked Apr 02 '12Ed Scheinerman
31 ● 1 ● 2 ● 5
I usually use scipy for this:
posted Apr 02 '12DSM
4882 ● 12 ● 65 ● 105
Since you like R:
You do get Python ints, not Sage Integers, though that wouldn't be hard to change with a list comprehension, presumably.
Asked: Apr 02 '12
Seen: 1,131 times
Last updated: Apr 02 '12
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.