Efficiency and correctness of my randomized selection algorithm Instead of picking a random pivot I'm shuffling the array beforehand. Does it count as randomization and is it efficient to shuffle or pick a random pivot and is my implementation pythonic?

Problem

Algorithm

from random import shuffle


def _partition(arr, lo, hi, pivot):
    p = arr[pivot]
    arr[hi - 1], arr[pivot] = arr[pivot], arr[hi - 1]
    i = lo - 1
    for j in xrange(lo, hi):
        if arr[j] &lt;= p:
            i += 1
            arr[i], arr[j] = arr[j], arr[i]
    return i


def select(arr, lo, hi, spos):
    assert lo &lt;= spos &lt; hi
    shuffle(arr)  # here's your randomization.
    while True:
        pos = _partition(arr, lo, hi, lo)
        if pos == spos:
            return arr[pos]
        elif pos &lt; spos:
            lo = pos + 1
        else:
            hi = pos
You should learn about how to benchmark your code, from my benchmark, shuffling makes the algorithm slower:

from random import shuffle,randint
import time

def _partition(arr, lo, hi, pivot):
    p = arr[pivot]
    arr[hi - 1], arr[pivot] = arr[pivot], arr[hi - 1]
    i = lo - 1
    for j in xrange(lo, hi):
        if arr[j] &lt;= p:
            i += 1
            arr[i], arr[j] = arr[j], arr[i]
    return i


def select(arr, lo, hi, spos,shuffling=None):
    assert lo &lt;= spos &lt; hi
    if shuffling: shuffle(arr)  # here's your randomization.
    while True:
        pos = _partition(arr, lo, hi, lo)
        if pos == spos:
            return arr[pos]
        elif pos &lt; spos:
            lo = pos + 1
        else:
            hi = pos

def random_list(length):
    return [randint(1,100) for _ in range(length)]

start = time.time()
results = []
for _ in range(10000):
    results.append(select(random_list(10),1,5,1,shuffling=True))
print("With shuffling: ",time.time()-start)

start = time.time()
results = []
for _ in range(10000):
    results.append(select(random_list(10),1,5,1,shuffling=False))
print("WithOUT shuffling: ",time.time()-start)