#xuanhao.py
import random
def getResultStr(totalCount,resultCount):
elements = [x+1 for x in range(totalCount)]
retStr = ''
for i in range(resultCount):
res = elements[random.randint(0,len(elements)-1)]
elements.remove(res)
retStr += ' ' +str(res)
return retStr
#shuangseqiu.py
import xuanhao
print xuanhao.getResultStr(33,6)
print xuanhao.getResultStr(16,1)
#daletou.py
import xuanhao
print xuanhao.getResultStr(35,5)
print xuanhao.getResultStr(12,2)
daletou.py 运行 显示:
>>>
23 29 33 11 5
1 2
>>>
运行显示:
>>>
16 15 31 29 1 12
14
>>>