fix bug in random sampling