Add mac support, improve the random generator