x = c(1,0) |

In Python I just make a list or string with the elements inserted according to the desired probability, then use random.choice.

import random, math |

To simulate a DNA sequence, they use the integers 1 to 4, because R doesn't deal with strings or characters very gracefully.

set.seed(13) |

In Python

b = 'ACGT' |

In example 2.2, they generate a sequence from the binomial distribution

x <- rbinom(2000,1000,0.25) |

The math module doesn't have a mean function so we define some simple statistical functions:

def mean(L): |

We fake the binomial distribution like this:

import random, math |

And finally, we'd like to generate a histogram of the values (I'll plot the R results):

b = max(x) - min(x) + 1 |

Here it is: