python随机产生4个互不相等的随机数

从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
上一篇:git统计报告


下一篇:解决WinForm(C#)中MDI子窗体最大化跑偏的问题