Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: shuffling (randomizing) a series

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52896] Re: [mg52857] shuffling (randomizing) a series
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Thu, 16 Dec 2004 03:40:32 -0500 (EST)
  • References: <200412150926.EAA10600@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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

Needs["DiscreteMath`Combinatorica``"]
p=RandomPermutation[10^7];

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:

Table[list[[p[[i]]]],{i,Length[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

strm=OpenRead["filename"];
SetStreamPosition[strm,p[[n]]*(n-1)*size];
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.

Regards,

Ssezi


  • 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