我正在尝试用Python为我的班级创建一个座位计划生成器。我有4个字符串列表:9个女孩,9个男孩,10个女孩和10个男孩。然后我生成了一个伪随机整数,并以稍微格式化的结果打印结果。这些结果总是重叠,我该怎样避免这种情况?我将尝试实施关于不同组的一些规则,这就是为什么它们在4个列表中。
答案 0 :(得分:0)
尝试使用跳远以避免重叠
random.sample(population, k)
或
case 8:
//Largest allowable integer in javascript is 2^53-1 so gonna have to use one less bit for now
raw = dataview.getFloat64(offset);
var firstInt = dataview.getUint32(offset) & 0x000FFFFF;
var secondInt = dataview.getUint32(offset + 4);
vint_data = (firstInt << 8) | secondInt;
break;
答案 1 :(得分:0)
尝试使用random.sample():
>>> random.sample(["Jane","John","Jack","Jill"], 4)
['Jane', 'John', 'Jill', 'Jack']
>>> random.sample(["Jane","John","Jack","Jill"], 4)
['John', 'Jill', 'Jane', 'Jack']
>>> random.sample(["Jane","John","Jack","Jill"], 4)
['Jill', 'John', 'Jane', 'Jack']
>>> random.sample(["Jane","John","Jack","Jill"], 4)
['Jane', 'Jill', 'John', 'Jack']
>>> random.sample(["Jane","John","Jack","Jill"], 4)
['Jane', 'John', 'Jack', 'Jill']