Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shuffle an array with python, randomize array item order with python

What's the easiest way to shuffle an array with python?

like image 332
davethegr8 Avatar asked Jan 23 '09 18:01

davethegr8


People also ask

How do you randomize an array order in Python?

Shuffle an Array in Python Using the random.shuffle() method takes a sequence as input and shuffles it. The important thing to note here is that the random. shuffle() does not return a new sequence as output but instead shuffles the original sequence.

How do I shuffle the order of a list in Python?

To shuffle strings or tuples, use random. sample() , which creates a new object. random. sample() returns a list even when a string or tuple is specified to the first argument, so it is necessary to convert it to a string or tuple.

How do you shuffle the order of an array?

The first and simplest way to shuffle an array in JavaScript is to provide a custom function to a . sort() . const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const shuffledArray = array. sort((a, b) => 0.5 - Math.


1 Answers

import random random.shuffle(array) 
like image 166
David Z Avatar answered Oct 14 '22 09:10

David Z