先测试把100个数字0-99个,按7:2:1数量比例分配给a集,b集,c集,其中单个样本随机分配
import random
totalnum = 100
t1 = totalnum*0.1
t2 = totalnum*0.2
t3 = totalnum*0.7
a = set()
b = set()
c = set()
while(len(a)<t1):
x = random.randint(0,totalnum)
if x not in a:
a.add(x)
while(len(b)<t2):
x = random.randint(0,totalnum)
if x in a:
continue
if x not in b:
b.add(x)
for x in range(totalnum):
if x in a or x in b:
continue
else:
c.add(x)
print "a = ",a,len(a)
print "b = ",b,len(b)
print "c = ",c,len(c)
wu@wu-X555LF:~$ python random_test.py
a = set([44, 42, 12, 46, 15, 49, 19, 20, 14, 59]) 10
b = set([35, 36, 86, 39, 8, 9, 75, 76, 13, 77, 29, 24, 78, 3, 53, 22, 88, 68, 93, 7]) 20