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
}
}
Source: stackoverflow.com
Related Query
- Displaying random rows without repetition
- Check if IEnumerable has ANY rows without enumerating over the entire list
- EF - Update multiple rows in database without using foreach loop
- Picking random record from Entity Framework database without OrderBy
- Get random number of rows from SQL Server table
- Efficiently select random rows from large resultset with LINQ (ala TABLESAMPLE)
- Return Random Rows using an IQueryable
- Using LINQ to Entity without putting all rows in memory
- Multiple rows update without select
- Accessing Rows In A LINQ Result Without A Foreach Loop?
- Order a list with unique rows with a given row as first item, then reorder the list but without the first row
- How To group by a list of list and merge it into single list without repetition in C#?
- How can I generate combinations of 5 numbers taken 3 at a time without repetition using Linq?
- strange behavior in linq to sql to return all rows without filtering
- Combinations without repetition with specific number
- Get the count of rows of a DataTable using Linq or without using Linq
- Studying an Idea for extract random rows with LINQ
- ASP.Netcore MVC - Razor Displaying expense totals for categories by Month/Year rows and total expenses per month using efcore
- Build pairs out of list - without repetition
- Add multiple rows into datatable with the same data without looping
- Linq to Entities figure out count of rows without returning rows
- How to rank the list of random value without changing their index in C#
- Linq order by random without GUID
- WPF Datagrid has data in the rows but not displaying text
- Displaying multiple rows in a single View using Details Scaffolding
- Pulling all rows from database then displaying them to a table
- LINQ returning only rows without any null fields, how to get the null fields too?
- Deleting rows with same foreign key but different primary key without affecting each other
- Get 3 random values from a Dictionary (with tuple string[]) without duplicates
- Select rows without joining other tables regarding other tables
More Query from same tag
- Store update LINQ query and pass to json
- Split a list into multiple lists at increasing sequence broken
- Converting string to int in linq
- Transform this list using linq?
- C# - LINQ Statements with OR clauses
- LINQ - ConflictChangeException
- WCF, Linq Error:cannot implicitly convert type System.linq.iorderedQueryable<> to System.Collection.Generic.List<>
- LINQPAD - Read in a csv and store columns into lists
- Improving conversion from List to List<Dictionary<string,string>> with Linq
- multi level parent child sorting
- C# Linq Where Date Between 2 Dates
- Query a dictionary to get top 3 most common elements
- LINQ to Entities does not recognize the method 'System.Windows.Forms.DataGridViewCell get_Item(Int32)' method
- In operator using linq query
- Assign multiple values using linq
- Query Performance for multiple IQueryable in .NET Core with LINQ
- LINQ SUM data based on Array Results
- Entity Framwork Core + Linq: How do I get the entire entity that has the max value? Looking for a more elegant solution
- Issue in check Null condition using linq query
- group by select max in linq
- Linq two left outer join Error Non-static method requires a target
- Split String to array and Sort Array
- Merging of xml documents
- Stored procedure or LINQ?
- Dynamic linq query string not working
- Extract values from XML with linq query
- Store Linq Query in a list c#
- How to transform grouping with MAX from sql to linq query
- How ToLookup() with multiple indexes?
- How to find if a string exists only with numbers? (in LINQ)