Re: [PD] Shuffling arrays

2010-10-05 Thread Andrew Faraday

Yeah, urn looks like the simplest way to achieve what I want to do. Cheers, guys

 Date: Tue, 5 Oct 2010 08:58:51 +0200
 From: f...@footils.org
 To: pd-list@iem.at
 Subject: Re: [PD] Shuffling arrays
 
 Hi,
 
 On Mon, Oct 04, 2010 at 03:07:52PM +0200, Lorenzo wrote:
  I guess if you only need to *read* elements of the array you could
  also use the [urn] object from cyclone feeding a [tabread].
 
 Or the [urn] from Zexy or urne.pd from purepd or the identical c_urn.pd
 from the rj library, the abstractions being pure vanilla
 implementations.
 
 Ciao
 -- 
 Frank
 
 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - 
 http://lists.puredata.info/listinfo/pd-list
  ___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-05 Thread Claude Heiland-Allen

On 04/10/10 16:06, martin.pe...@sympatico.ca wrote:


That's a bad way to shuffle,


The same way that it's a really bad way to sort - maybe it could be 
classed as a bogobubblesort.  I chose to do it that way for aesthetic 
purposes (a jumbled sequence gradually returns to order) rather than 
efficiency...


This might be relevant if you value correctness:
http://okmij.org/ftp/Haskell/perfect-shuffle.txt


as it can swap things back again and generally reduce the randomness, the way 
someone who is good at shufflng cards can put them all back the way they 
started while appearing to mix them up.

A better way is to start at the beginning of the array, swap the first item 
with one of the remaining items, then swap the second item, up to the end.

Martin

Claude wrote:

On 03/10/10 23:21, Andrew Faraday wrote:


Hey Guys
I've recently come across the .shuffle method in Ruby which randomly re-orders 
the content of an array. Does anyone know of a way to do this in Pd, that is, 
either change the order of notes within an array or output them in a random 
order (without repeating any part of it)?
Help would be appreciated
Andrew


You can pick pairs of indices at random and swap them with
tabread/tabwrite; repeat to shuffle more.

I used a similar technique to gradually sort an array (swap random
elements only if they are out of order):

https://code.goto10.org/svn/maximus/2007/clouds-are-made-of-water/
http://www.archive.org/details/ClaudiusMaximus_-_Clouds_Are_Made_Of_Water
(track 5)


Claude
--
http://claudiusmaximus.goto10.org

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -  
http://lists.puredata.info/listinfo/pd-list





___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-05 Thread Mathieu Bouchard

On Tue, 5 Oct 2010, Claude Heiland-Allen wrote:

The same way that it's a really bad way to sort - maybe it could be classed 
as a bogobubblesort.


That sort is still just O(n²) in time, isn't it ? And it can finish 
faster than the bubble sort. Does it often do ?


If you want a really slow sort, the bumblesort is rated O(n²*2^n)...


This might be relevant if you value correctness:
http://okmij.org/ftp/Haskell/perfect-shuffle.txt


It makes a strawman example about sorting with a random key bit being 
attached to each element. No-one would use a random key. The rest of the 
argument is good, but the reader should consider what happens with 32-bit 
ints, and if that's not enough, 64-bit ints... In any case, if I were to 
code something in C++ for shuffling, I wouldn't pick this and would pick a 
fair shuffling instead, but it might be more because this is O(n*log(n)) 
and fair shufflings are doable in O(n).


Btw, when you use [random n], did you wonder about the fairness of the 
result ? note that n is usually not a divisor of 2^32. I think that the 
fairness-error it introduces is bigger than the one in sorting on random 
32-bit keys (but it shows more when n is high).


A better way is to start at the beginning of the array, swap the first 
item with one of the remaining items, then swap the second item, up to 
the end.


Yes, that's O(n), and that's what I'd use for a C++ version.

 ___
| Mathieu Bouchard -- Villeray, Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-05 Thread Mathieu Bouchard

On Tue, 5 Oct 2010, Mathieu Bouchard wrote:

It makes a strawman example about sorting with a random key bit being 
attached to each element. No-one would use a random key.


erratum: no-one would use a single bit as a random key.

 ___
| Mathieu Bouchard -- Villeray, Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-04 Thread Lorenzo

 tim vets wrote:

William Brent's tabletool ?
http://williambrent.conflations.com/pages/research.html
gr,
Tim

2010/10/4 Andrew Faraday jbtur...@hotmail.com 
mailto:jbtur...@hotmail.com


Hey Guys

I've recently come across the .shuffle method in Ruby which
randomly re-orders the content of an array. Does anyone know of a
way to do this in Pd, that is, either change the order of notes
within an array or output them in a random order (without
repeating any part of it)?

I guess if you only need to *read* elements of the array you could also 
use the [urn] object from cyclone feeding a [tabread].


Lorenzo



Help would be appreciated

Andrew

___
Pd-list@iem.at mailto:Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -
http://lists.puredata.info/listinfo/pd-list



___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -  
http://lists.puredata.info/listinfo/pd-list


___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-04 Thread Mathieu Bouchard

On Sun, 3 Oct 2010, Andrew Faraday wrote:

I've recently come across the .shuffle method in Ruby which randomly 
re-orders the content of an array. Does anyone know of a way to do this 
in Pd, that is, either change the order of notes within an array or 
output them in a random order (without repeating any part of it)? 


there's an example of shuffling at the top of [#sort]'s help file :

  http://gridflow.ca/help/%23sort-help.html

 ___
| Mathieu Bouchard -- Villeray, Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-04 Thread Claude Heiland-Allen

On 03/10/10 23:21, Andrew Faraday wrote:


Hey Guys
I've recently come across the .shuffle method in Ruby which randomly re-orders 
the content of an array. Does anyone know of a way to do this in Pd, that is, 
either change the order of notes within an array or output them in a random 
order (without repeating any part of it)?
Help would be appreciated
Andrew  


You can pick pairs of indices at random and swap them with 
tabread/tabwrite; repeat to shuffle more.


I used a similar technique to gradually sort an array (swap random 
elements only if they are out of order):


https://code.goto10.org/svn/maximus/2007/clouds-are-made-of-water/
http://www.archive.org/details/ClaudiusMaximus_-_Clouds_Are_Made_Of_Water
(track 5)


Claude
--
http://claudiusmaximus.goto10.org

___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-04 Thread martin.peach

That's a bad way to shuffle, as it can swap things back again and generally 
reduce the randomness, the way someone who is good at shufflng cards can put 
them all back the way they started while appearing to mix them up.

A better way is to start at the beginning of the array, swap the first item 
with one of the remaining items, then swap the second item, up to the end.

Martin

Claude wrote:
 On 03/10/10 23:21, Andrew Faraday wrote:

 Hey Guys
 I've recently come across the .shuffle method in Ruby which randomly 
 re-orders the content of an array. Does anyone know of a way to do this in 
 Pd, that is, either change the order of notes within an array or output them 
 in a random order (without repeating any part of it)?
 Help would be appreciated
 Andrew

 You can pick pairs of indices at random and swap them with
 tabread/tabwrite; repeat to shuffle more.

 I used a similar technique to gradually sort an array (swap random
 elements only if they are out of order):

 https://code.goto10.org/svn/maximus/2007/clouds-are-made-of-water/
 http://www.archive.org/details/ClaudiusMaximus_-_Clouds_Are_Made_Of_Water
 (track 5)


 Claude
 --
 http://claudiusmaximus.goto10.org

 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management - 
 http://lists.puredata.info/listinfo/pd-list
  
___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-04 Thread Mathieu Bouchard

On Mon, 4 Oct 2010, martin.pe...@sympatico.ca wrote:

That's a bad way to shuffle, as it can swap things back again and 
generally reduce the randomness, the way someone who is good at shufflng 
cards can put them all back the way they started while appearing to mix 
them up.


But the programme is not meaning to swap things back. If things are 
swapped back in a random fashion, where the probability of swapping back 
follows from a sequence of independent uniform random-variables, what's 
the problem with that ? It's like the probability of getting twice the 
same dice number in a row, there's a certain amount of random repetition 
that is considered normal.


How would you write a formal proof of what you say ?

But I also believe that the quickest perfectly fair shuffle is done a lot 
more like [urn] than like swapping random elements. The latter converges 
towards being fair eventually, whereas [urn] is fair in N steps if 
random() is fair. The former doesn't take so many steps, but one has to 
decide where to stop swapping, and that's not a decision I'd like to be 
making, so I prefer [urn]-like processes (or similarly, [#grade]-like 
processes).


 ___
| Mathieu Bouchard -- Villeray, Montréal, QC___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


[PD] Shuffling arrays

2010-10-03 Thread Andrew Faraday

Hey Guys
I've recently come across the .shuffle method in Ruby which randomly re-orders 
the content of an array. Does anyone know of a way to do this in Pd, that is, 
either change the order of notes within an array or output them in a random 
order (without repeating any part of it)? 
Help would be appreciated
Andrew___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list


Re: [PD] Shuffling arrays

2010-10-03 Thread tim vets
William Brent's tabletool ?
http://williambrent.conflations.com/pages/research.html
http://williambrent.conflations.com/pages/research.htmlgr,
Tim

2010/10/4 Andrew Faraday jbtur...@hotmail.com

  Hey Guys

 I've recently come across the .shuffle method in Ruby which randomly
 re-orders the content of an array. Does anyone know of a way to do this in
 Pd, that is, either change the order of notes within an array or output them
 in a random order (without repeating any part of it)?

 Help would be appreciated

 Andrew

 ___
 Pd-list@iem.at mailing list
 UNSUBSCRIBE and account-management -
 http://lists.puredata.info/listinfo/pd-list


___
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management - 
http://lists.puredata.info/listinfo/pd-list