從0~9中隨機產生4個互不相等的數,
方法一:
import random s=[] while(len(s)<4): x=random.randint(0,9) if x not in s: s.append(x) print(s)
方法二:
import random result=[] x=range(10) for i in range(4): t=random.randint(i,9) temp=x[i] x[i]=x[t] x[t]=temp result.append(x[i]) print result