finished implementing a random sampling algorithm