Changed calls to rand() to fix compatability with Ruby1.8