refactor of Random class