1
c Jun 26, 2012 >>> import random
>>> names = 'abcdefg' >>> print random.sample(names, 2) ['c', 'b'] |
2
nigelvon Jun 26, 2012
python不熟,给你个思路吧,名字放到一个数组里。
随机抽一个元素,然后从数组中删掉,直到抽到想要的数量为止。 |
5
ayanamist Jun 26, 2012 |
7
clowwindy Jun 26, 2012
import random
with open('a.txt') as f: print random.sample(f.read().split(' '), 2) |
9
c Jun 26, 2012 |
10
Eyon OP @clowwindy
with open('/Users/eyon/names.txt') as f: ... print random.sample(f.read().split(' '), 2) File "<stdin>", line 2 print random.sample(f.read().split(' '), 2) ^ IndentationError: expected an indented block |
11
aa88kk Jun 26, 2012 |
14
loading Jun 26, 2012
我以前用的是网页,用js写的,能比较美观!
|
15
winix Jun 26, 2012 http://winix.name/lotto/ 去年公司年会时用JS写的,去掉了背景和名单。
1、空格键开始,再次按空格抽一个奖 2、z键暂停(防止误按) 3、名单单独放在一个js文件里,第一列是手机号或者工号什么的,第二列是姓名 4、支持作弊,目前是将特殊号码的16进制写在index.html里(一眼看不出来是谁),抽奖时按对应的数字键,从1开始 5、窗口误关闭时会提醒 |
16
karma Jun 26, 2012
需要设计一等奖永远抽不中的功能么?
|