improved the random functions