Re: Re: shuffling (randomizing) a series

*To*: mathgroup at smc.vnet.net*Subject*: [mg52931] Re: [mg52896] Re: [mg52857] shuffling (randomizing) a series*From*: DrBob <drbob at bigfoot.com>*Date*: Fri, 17 Dec 2004 05:18:52 -0500 (EST)*References*: <200412150926.EAA10600@smc.vnet.net> <200412160840.DAA27284@smc.vnet.net>*Reply-to*: drbob at bigfoot.com*Sender*: owner-wri-mathgroup at wolfram.com

The Needs statement has an extra "`" at the end, which keeps it from working: >> Needs["DiscreteMath`Combinatorica``"] Also, the following: >> Table[list[[p[[i]]]],{i,Length[list]}] can be replaced by the much simpler (and faster) list[[p]] For instance: (inputs) Needs["DiscreteMath`Combinatorica`"] list = 1/Range@10 p = RandomPermutation@Length@list list[[p]] (outputs) {1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10} {1, 8, 7, 3, 9, 10, 4, 2, 6, 5} {1, 1/8, 1/7, 1/3, 1/9, 1/10, 1/4, 1/2, 1/6, 1/5} Bobby On Thu, 16 Dec 2004 03:40:32 -0500 (EST), Sseziwa Mukasa <mukasa at jeol.com> wrote: > > 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 > > > > -- DrBob at bigfoot.com www.eclecticdreams.net

**References**:**shuffling (randomizing) a series***From:*George Szpiro <george@netvision.net.il>

**Re: shuffling (randomizing) a series***From:*Sseziwa Mukasa <mukasa@jeol.com>