try to implement xnrand's fix