# In Place Uniform Shuffle

DevFeed: [In Place Uniform Shuffle](<https://devfeed.tech/articles/in-place-uniform-shuffle-40266.md>)

Original publisher: [Read original article](<https://www.jeremykun.com/2012/03/18/in-place-uniform-shuffle/>)

Published: 2012-03-18T20:33:42Z

Content type: tutorial

Language: en

Sources: [Jeremy Kun](<https://devfeed.tech/sources/jeremy-kun.md>)

Topics: [Algorithms](<https://devfeed.tech/topics/algorithms.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [fairness](<https://devfeed.tech/tags/fairness.md>), [permutations](<https://devfeed.tech/tags/permutations.md>), [python](<https://devfeed.tech/tags/python.md>)

## AI overview

A Python implementation of an in-place uniform shuffle is presented. The article explains why uniform randomness matters for shuffling and derives a process that selects a random remaining element at each position, using constant extra space and linear time.

## Source excerpt

Problem: Write a program that shuffles a list. Do so without using more than a constant amount of extra space and linear time in the size of the list. Solution: (in Python) import random random.seed() def shuffle(myList): n = len(myList) for i in xrange(0, n): j = random.randint(i, n-1) # randint is inclusive myList[i], myList[j] = myList[j], myList[i] Discussion: Using a computer to shuffle a deck of cards is nontrivial at first glance for the following reasons.