Removed use of c function rand().

Uses modern c++ random generator instead.