random generator and permuation