from random import * poss = [['u','U'],['r','R']] scramble='' num=4 axis=2 for t in range(25): ax=randint(0,1) y=randint(0,1) if ax == axis: while y==num: y=randint(0,1) num=y axis=ax scramble=scramble+poss[ax][y]+' ' print scramble