. , , , -. [97, 32, 17, 15, 57, 97, 63, 72, 60, 8] shuffle. shuffle ( , ) . , , [97, 32, 17, 15, 57, 97, 63, 72, 60, 8]. , , , .
, :
[31, 64, 88, 7, 68, 85, 69, 3, 15, 47]
[31, 64, 88, 47, 68, 85, 69, 3, 15, 7]
[31, 64, 15, 47, 68, 85, 69, 3, 88, 7]
[31, 64, 15, 47, 68, 85, 69, 3, 88, 7]
[31, 64, 69, 47, 68, 85, 15, 3, 88, 7]
[31, 64, 85, 47, 68, 69, 15, 3, 88, 7]
[31, 64, 85, 47, 68, 69, 15, 3, 88, 7]
[31, 64, 85, 47, 68, 69, 15, 3, 88, 7]
[31, 85, 64, 47, 68, 69, 15, 3, 88, 7]
[85, 31, 64, 47, 68, 69, 15, 3, 88, 7]
:
def shuffle(self, x, random=None):
if random is None:
randbelow = self._randbelow
for i in reversed(range(1, len(x))):
j = randbelow(i+1)
x[i], x[j] = x[j], x[i]
print(x)
... other staff here
, [17, 72, 97, 8, 32, 15, 63, 97, 57, 60], [97, 15, 97, 32, 60, 17, 57, 72, 8, 63], " ". " "
, , , :
def work_with_rands(i, rands):
print('in function', i, rands)
def foo(a):
random.seed(random.randrange(999912)/9)
x = [None]*len(a)
for i in a:
_rand = random.randrange(len(a))
while x[_rand] is not None:
_rand = random.randrange(len(a))
x[_rand] = i
return x
def main():
rands = [random.randrange(100) for _ in range(10)]
with futures.ProcessPoolExecutor() as ex:
for i in range(4):
new_rands = foo(rands)
print("<{}> rands before submission: {}".format(i, new_rands ))
ex.submit(work_with_rands, i, new_rands )
<0> rands before submission: [84, 12, 93, 47, 40, 53, 74, 38, 52, 62]
<1> rands before submission: [74, 53, 93, 12, 38, 47, 52, 40, 84, 62]
<2> rands before submission: [84, 12, 93, 38, 62, 52, 53, 74, 47, 40]
<3> rands before submission: [53, 62, 52, 12, 84, 47, 93, 40, 74, 38]
in function 0 [84, 12, 93, 47, 40, 53, 74, 38, 52, 62]
in function 1 [74, 53, 93, 12, 38, 47, 52, 40, 84, 62]
in function 2 [84, 12, 93, 38, 62, 52, 53, 74, 47, 40]
in function 3 [53, 62, 52, 12, 84, 47, 93, 40, 74, 38]