Randomiser un liste d'éléments ColdFusion

Programmation Add comments

Voici une fonction toute simple et efficace qui permet de randomiser (je ne sais que ce n'est pas français mais il n'y a pas d'équivalent) l'ordre d'une liste d'éléments. Vous pouvez vous en servir, par exemple, pour faire varier l'ordre d'apparition de bannières sur un site.

function ListRandomiseur(ListARandomiser) {
    var local = StructNew();
    if (ArrayLen(Arguments) gte 2) {
        local.iElements = Arguments[2];
    }
    else {
        local.iElements = ListLen(arguments.ListARandomiser);
    }
    local.lstRandom = "";
    local.ListARandomiser = ListSort(arguments.ListARandomiser, "text");
   
    // convertir en tableau par souci de rapidité
    local.TabARandomiser = ListToArray(local.ListARandomiser);
   
    for (local.i=1; local.i lte local.iElements; local.i = local.i+1) {
        if (ArrayLen(local.TabARandomiser) neq 0) {
            local.iRandom = RandRange(1, ArrayLen(local.TabARandomiser));
            local.lstRandom = ListAppend(local.lstRandom, local.TabARandomiser[local.iRandom]);
            ArrayDeleteAt(local.TabARandomiser, local.iRandom);
        }
        else {
            // plus d'éléments dans la liste
            break;       
        }
    }
    return(local.lstRandom);
}

Utilisation : <CFSET LeResultat = ListRandomiseur(votreListe)>

4 responses to “Randomiser un liste d'éléments ColdFusion”

  1. OSBORNETammie25 Says:
    Have no cash to buy a car? Do not worry, just because it's possible to receive the <a href="http://lowest-rate-loans.com/topics/credit-loans">credit loans</a> to work out all the problems. Thus take a sba loan to buy all you require.
  2. chanel bags 2010 Says:
    You write good articles,I like your essay.
  3. coach outlet online Says:
    http://www.gucci-outlet.us/ gucci handbags outlet
    http://www.gucci-outlet.us/ gucci outlet
    http://www.gucci-outlet.us/ gucci handbags
    http://www.coach-bags-outlet.com/ coach bags onsale
    http://www.coach-bags-outlet.com/ coach outlet store
    http://www.coach-bags-outlet.com/ cheap coach bags
  4. ed hardy Says:
    http://www.ed-hardy.cc ed hardy
    http://www.ed-hardy.cc/ed-hardy-clothing.html ed hardy clothing
    http://www.cheap-mbt-shoes.net mbt
    http://www.cheap-mbt-shoes.net mbt shoes
    http://www.cheap-mbt-shoes.net walking shoes
    http://www.newaj.com air jordan
    http://www.newaj.com air jordan shoes
    http://www.saleairmaxshoes.com air max shoes
    http://www.saleairmaxshoes.com Air max
    http://www.monclerjacketsstore.com Moncler
    http://www.monclerjacketsstore.com Moncler Outlet
    http://www.monclerjacketsstore.com Moncler Jackets
    http://www.monclerjacketsstore.com Moncler Store

Leave a Reply





Powered by Mango Blog. Design and Icons by N.Design Studio