MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: shuffling (randomizing) a series

  • To: mathgroup at
  • Subject: [mg52896] Re: [mg52857] shuffling (randomizing) a series
  • From: Sseziwa Mukasa <mukasa at>
  • Date: Thu, 16 Dec 2004 03:40:32 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

On Dec 15, 2004, at 4:26 AM, George Szpiro wrote:

> Hello,
> I would like to put a series of numbers (of the order of 10^7 numbers) 
> into
> random order, i.e., to shuffle it. In Excel I would simply add a 
> column next
> to the column with the data, and then sort by the random number. But I 
> could
> only do this for 64000 numbers. How can I do that in Mathematica for a 
> file with a
> much larger series?

Without knowing the larger context of what you are doing it's hard to 
answer your question.  The expressions


will give a random permutation of length 10^7.  It takes about a minute 
to compute the permutation of that length on my machine.  You can then 
use the permutation to access your list.  Assuming it's in a variable 
named list:


will return your list in random order.  If you prefer not to read the 
entire list into memory, create the permutation as above then use an 
expressions of the form

val=Read[strm, type];

will return the nth element of the permuted list where size is the size 
in bytes of each value and type is set appropriately.  Since I don't 
know how the list is to be used it's hard to write expressions that 
optimally trade off disk access versus memory use.



  • Prev by Date: Re: Re: defining variables as Real
  • Next by Date: Re: about Package
  • Previous by thread: Re: shuffling (randomizing) a series
  • Next by thread: Re: Re: shuffling (randomizing) a series