In [10]:
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

In [11]:
size = len(l)
size


Out[11]:
10

In [12]:
import random

In [18]:
## com repetidos
result = []
for i in range(len(l)):
    position = int(random.random() * size)
    result.append(l[position])

In [19]:
result


Out[19]:
[2, 5, 0, 4, 0, 4, 6, 2, 0, 4]

In [22]:
## sem repetidos bigO(n**2)
result = []
for i in range(len(l)):
    while True:
        position = int(random.random() * size)
        value = l[position]
        if value not in result:
            break
    result.append(value)

In [23]:
result


Out[23]:
[1, 2, 0, 3, 8, 7, 9, 5, 4, 6]

In [26]:
## sem repetidos bigO(n) space(n)
result = []
has_map = {}
for i in range(len(l)):
    while True:
        position = int(random.random() * size)
        value = l[position]
        if value not in has_map:
            break
    has_map[value] = True
    result.append(value)

In [27]:
result


Out[27]:
[9, 8, 7, 2, 3, 4, 5, 1, 6, 0]

In [30]:
## sem repetidos O(n)

result = l[:]
for i in range(2 * len(l), 0, -1):
    p1 = int(random.random() * size)
    p2 = int(random.random() * size)
    aux = result[p1]
    result[p1] = result[p2]
    result[p2] = aux
result


Out[30]:
[2, 6, 7, 4, 1, 3, 5, 8, 0, 9]

In [32]:
## sem repetidos O(n)

result = l[:]
for i in range(0, len(l)):
    p = int(random.random() * size)
    aux = result[i]
    result[i] = result[p]
    result[p] = aux
result


Out[32]:
[8, 3, 4, 2, 6, 5, 7, 1, 0, 9]

In [ ]: