python随机生成彩票号码

看了oschina的一段代码,于是也模仿了下。原文地址是:http://www.oschina.net/code/snippet_41847_2226

我模仿的代码如下:

#coding=utf-8
import random

def xuanhao(total, count):
    element = [x+1 for x in range(total)]
    result = []
    for i in range(count):
        res = element[random.randint(0, len(element) - 1)]
        element.remove(res)
        result.append(res)

    return result

print xuanhao(33, 6)

PS,惭愧的是:说是模仿,不如说是照抄了。。。

posted on 2013-02-20 16:06  alexkh  阅读(522)  评论(0编辑  收藏  举报