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