Python's method of randomly generating lottery Numbers

  • 2020-04-02 14:38:33
  • OfStack

This article illustrates Python's method of randomly generating lottery Numbers. Share with you for your reference. The details are as follows:

A few days ago bought a while lottery on taobao, every time is the use of taobao machine, every time a bet. Later, I think it is not as interesting as to write a computer program

1. Xuanhao. Py files


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

2. Shuangseqiu. Py files


import xuanhao
print xuanhao.getResultStr(33, 6)
print xuanhao.getResultStr(16, 1)

3. Daletou. Py files


import xuanhao
print xuanhao.getResultStr(35, 5)
print xuanhao.getResultStr(12, 2)

I hope this article has helped you with your Python programming.


Related articles: