Ken Tucker Blog

Adventures in .net

Use Linq to create a random list of numbers

Monday, December 3, 2007

Here is a simple linq query which places the numbers from 1 and 150 in a random order

 

Dim r As New Random(Now.Ticks Mod Int32.MaxValue)

Dim rndLst = From l In (From num In Enumerable.Range(1, 150) _
             Select New With {.Num = num, .pos = r.Next(1, 150)}) _
             Order By l.pos _
             Select l.Num

For Each i In rndLst
    Console.WriteLine(i)
Next


kick it on DotNetKicks.com
Tags: , ,
Filed Under: Linq, VB, VS 2008

Comments (4) -

busby seo test said:

really?how it work?tell me more bout it.thanks

Kabon said:

I think Ken is already clear explained how it work in this article.

Comments are closed