# select唯一的随机数字

``Dim RndNumber As Random Dim num,num2 As Integer RndNumber = New Random num = RndNumber.Next(1, 11) num2 = RndNumber.Next(1, 11)` `

` `Private RNG = New Random()` `

### LINQ

` `Dim nums = Enumerable.Range(1, 10). OrderBy(Function(r) RNG.Next). Take(3). ToArray()` `

` `Dim winners = Enumerable.Range(1, 69).OrderBy(Function(r) RNG.Next()).Take(5).ToArray() Dim powerball = Enumerable.Range(1, 26).OrderBy(Function(r) RNG.Next()).Take(1).First` `

### 手册

` `' picked value storage Dim picks As New List(Of Int32) Dim pick As Int32 ' current candidate Do pick = RNG.Next(1, 11) If picks.Contains(pick) = False Then picks.Add(pick) End If Loop Until picks.Count = 3` `

` `' create pool of 2 values each for 1-13 Dim nums = Enumerable.Range(1, 13).ToArray() ' concat the set to make 2 of each value, randomize Dim pool = nums.Concat(nums).OrderBy(Function(r) RNG.Next).ToArray()` `

### “用尽”精选

` `' create, randomize pool of 100 ints Dim nums = Enumerable.Range(1, 100).OrderBy(Function(r) RNG.Next).ToArray ' use array to create Stack<T> Dim shoe As New Stack(Of Int32)(nums) ' same as: Dim shoe = New Stack(Of Int32)(Enumerable.Range(1, 100). OrderBy(Function(r) RNG.Next).ToArray())` `

` `Console.WriteLine(shoe.Count) For n As Int32 = 1 To 3 Console.WriteLine("Picked #{0}", shoe.Pop) Next Console.WriteLine(shoe.Count)` `

100

97