impl. custom random() function.