This is a simple generic implementation of Gillespie algorithm.