Randomizing an array

前端 未结 3 1688
栀梦
栀梦 2021-01-22 07:57

I wish to implement the Dr.D.E.Knuth\'s Subtractive RANDOM number generation algorithm. I wish to implement an ATM panel on which when very time user log-in the buttons will be

3条回答
  •  感动是毒
    2021-01-22 08:50

    There are quite some "shuffle" algorithms (search Fisher-Yates for example) and they are usually not difficult to implement. The EASIEST (imho) way, ist to use LINQ:

    Dim r As New Random
    Dim out = (From b In btnArray Order By r.Next Select b).ToArray
    

    Maybe the question is not clear: Do you want to shuffle the POSITIONS of the buttons or do you want to shuffle the CONTENT (buttons) of the Array?

提交回复
热议问题