How to Choose Random number from given list of numbers in VB.Net

后端 未结 4 603
清酒与你
清酒与你 2021-01-29 03:35

I want to create a random number generator in VB.NET But from my own given list of numbers

Like Chose random numbers fro

4条回答
  •  [愿得一人]
    2021-01-29 03:47

    I would create a random number generator to generate a random number in the range of the list/array length, then use the result to point to the index of your number list.

    Dim numbers As Integer() = New Integer() {1,2,5,6,7,8,12,43,56,67}
    
    Dim randomKey = numbers(CInt(Rnd() * numbers.length))
    

    *Edited based on Lajos Arpad's answer of how to get the random number

提交回复
热议问题