TOMBOLA!! randomize text waves, excellent to choose the presenter or make a cookies list for lab meetings

I accidantally deleted the following code snipped posted July 5th, 2012 by purozongo. Fortunately, Adam Light found it in Google's cache, so here is it again:
//      ***TOMBOLA!!!***
// TOMBOLA!!! randomize the text wave "lista" in the wave "resultado"
// excelent to choose the presenter or cookies list for the lab seminars
// Germán Fernández, <a href="; rel="nofollow"></a>, @2012
Function Tombola(lista)
Wave/T lista
variable i,j,k
string comp
Make/T/O/N=(numpnts(lista)) resultado=""
    j=round(abs((enoise( (numpnts(lista) -1) ) ) ) )
        if (k==1)
while (i<(numpnts(lista)))
Function check(onda,busca)
wave onda
string busca
FindValue/S=0 /TEXT=busca/TXOP=1  onda
if (V_value==(-1))
    return 1
    return 0

s.r.chinn's reply was also gone:

Here is an alternate approach that can be modified to randomize the order of ANY type of wave. The idea is to use a randomized index permutation wave as a sort key. No string comparisons are necessary. As above, a new re-ordered wave is created, but the input could also be re-ordered in place.

function SortNames(inList)  // re-orders input text wave by randomized sort key
    wave/T inList
    variable Npts = numPnts(inList)
    string outName = NameofWave(inList)+"_R"
    Duplicate/O inList, $outName    //  make new wave for re-ordered list
    WAVE outList = $outName
    shuffle(Npts)       //  create random sort key
    WAVE wPerm
    IndexSort wPerm, outList    //  re-arrange the output list entries
function shuffle(Npts)  //  perform a random permutation of indices 0...Npts-1
    variable Npts
    make/O/N=(Npts) wPerm = p   //  will be used as sort key
    variable i, j, temp
    for(i=Npts-1; i>0; i-=1)
        temp = wPerm[i]
        j = round(  i/2+enoise(i/2)  ) // pick random index from remaining choices
        wPerm[i] = wPerm[j] //  swap entries
        wPerm[j] = temp

For information on random shuffling, see

And here is what I actually wanted to add as another approach:

make/n=(numpnts(lista))/o keyw=abs(enoise(1))
duplicate/o lista resultado
sort keyw resultado

The method by awirsing is very concise and elegant. It should usually work.

I hate to be too picky, but in theory doesn't assigning any random values to elements of keyw allow for duplication of values? Extremely unlikely, but theoretically possible. How random is the sorting then if keyw may have some equal values?

My method constrains the random choices among remaining sort indices, not permitting index duplication.
Hi, thanks for repost my code.
s.r.chinn, i found very interesting your comment, if well this sniplet was writen just as a need of some method to sort our lab meetings could be a good method to "random sort" of text waves.

thanks for your comments.




Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More