rand fix. thanks to @QOAL