added rand_m algorithm