Simple algorithm question - how to reorder a sequence economically

Terry Jan Reedy tjreedy at udel.edu
Fri May 24 06:10:26 EDT 2013


On 5/24/2013 4:14 AM, Peter Brooks wrote:
> What is the easiest way to reorder a sequence pseudo-randomly?
>
> That is, for a sequence 1,2,3,4 to produce an arbitrary ordering (eg
> 2,1,4,3) that is different each time.
>
> I'm writing a simulation and would like to visit all the nodes in a
> different order at each iteration of the simulation to remove the risk
> of a fixed order introducing spurious evidence of correlation.

random module has a shuffle function I believe





More information about the Python-list mailing list