score:0

using system;
using system.collections.generic;
using system.linq;
using system.text;
using system.data;

namespace consoleapplication100
{
    class program
    {
        static void main(string[] args)
        {
            datatable dt = new datatable();
            dt.columns.add("adid", typeof(int));
            dt.columns.add("adname", typeof(string));
            dt.columns.add("adurl", typeof(string));
            dt.columns.add("credits", typeof (int));
            dt.rows.add(new object[] {1, "ad1", "abc.com", 10});
            dt.rows.add(new object[] {2, "ad2", "def.com", 40});
            dt.rows.add(new object[] {3, "ad3", "fgi.com", 30});
            dt.rows.add(new object[] {4, "ad4", "xyz.com", 40});

            random rand = new random();
            list<datarow> randomrows = dt.asenumerable().select(x => new { row = x, rand = rand.next() }).orderby(x => x.rand).select(x => x.row).tolist();
            datatable dt2 = randomrows.copytodatatable();

        }
    }
}

score:0

select top 10 * 
from   (select * 
        from   (select top 80 * 
                from   [table] 
                where  credit > 80 
                order  by newid())a 
        union all 
        select * 
        from   (select top 60 * 
                from   [table] 
                where  credit <= 80 
                       and credit > 60 
                order  by newid())b 
        union all 
        select * 
        from   (select top 40 * 
                from   [table] 
                where  credit <= 60 
                       and credit > 40 
                order  by newid())c 
        union all 
        select * 
        from   (select top 20 * 
                from   [table] 
                where  credit <= 40 
                order  by newid())d) t 
order  by newid() 

score:0

static ad select(this ireadonlylist<ad> ads)
{
    var range = ads.torange().tolist();
    int selectedindex = rnd.next(range.count);
    return ads[selectedindex];
}

static ienumerable<ad> selectads(this ienumerable<ad> ads, int selectcount)
{
    for (int i=0; i<selectcount; ++i)
    {
        var selectedad = ads.select();
        yield return selectedad;
        selectedad.isdisplayed = true; // to make sure it is not selected again
    }
}

Related Query

More Query from same tag