WebDec 27, 2016 · Then just order by ctx.Random (); this will do a random ordering at the SQL-Server courtesy of NEWID (). i.e. var cust = (from row in ctx.Customers where row.IsActive // your filter orderby ctx.Random () select row).FirstOrDefault (); Note that this is only suitable for small-to-mid-size tables; for huge tables, it will have a performance ... WebOct 31, 2008 · The Developer Fusion VB.Net to C# converter says that the equivalent C# code is: System.Random rnd = new System.Random (); IEnumerable numbers = Enumerable.Range (1, 100).OrderBy (r => rnd.Next ()); For future reference, they also have a C# to VB.Net converter. There are several other tools available for this as well. Share …
Clever way to shuffle a List in one line of C# code
WebApr 27, 2011 · Anton's got the idea, but you could make it a two-liner: public static IEnumerable Shuffle (this IEnumerable enumerable) { var r = new Random (); return enumerable.OrderBy (x=>r.Next ()).ToList (); } Unfortunately, it can't be lazily evaluated because r will be out of scope when it does execute. http://duoduokou.com/csharp/26461212222483197088.html songs with birds in the lyrics
C# 如何仅从字符串数组中拾取一次随机字符 …
WebJul 4, 2014 · The first variant, where I am using random.Next(), is working fine. But the variant, where I have call new Random().Next(), does NOT return random numbers; instead it returns a sequence of numbers from 0 to 20. Now my questions are: What is term to denote the second type of initialization of object new Random().Next() in C#? WebMar 6, 2024 · We first initialized the list list1 and then shuffled the list list1 with the random.next () function and the OrderBy () function of Linq in C#. The above method can also be used to shuffle a list of objects in C#. The following code example shows us how to shuffle a list of objects with Linq in C#. WebMay 29, 2011 · If you want to randomly re-order in place you should shuffle the list, usage with an extension method is then a simple one-liner. This assumes you already have an IList based collection. Usage: myList.Shuffle (); songs with birthday in it