.net - Random number generator check not working -


here code, i'm getting combinations contain same number more once check isn't working. need combination 1,2,3,4 in order. help.

dim rdmplace(3) string dim integer = 0 private sub rnd_btn_click(sender object, e eventargs) handles rnd_btn.click        count integer = 1 4         getrandom()         = + 1     next     entry1_txt.text = rdmplace(0)     entry2_txt.text = rdmplace(1)     entry3_txt.text = rdmplace(2)     entry4_txt.text = rdmplace(3) end sub sub getrandom()     randomize()     dim check integer = 1     dim rndvalue integer = cint(int((4 * rnd()) + 1))     each value integer in rdmplace         if value = rndvalue             getrandom()         end if     next     rdmplace(i) = rndvalue end sub  private sub reset_btn_click(sender object, e eventargs) handles reset_btn.click     entry1_txt.text = nothing     entry2_txt.text = nothing     entry3_txt.text = nothing     entry4_txt.text = nothing     = 0     clear integer = 0 3         rdmplace(clear) = nothing     next end sub 

i think intended put 4 consecutive numbers random order. instead generating random number 4 times (which duplicate given small range of numbers).

a solution follows:

dim list new list(of integer)({1, 2, 3, 4}) shuffle(list)  private shared _rng new random() public shared sub shuffle(of t)(alist ilist(of t))     dim n = alist.count     while (n > 1)         n -= 1         dim k integer = _rng.next(n + 1)         dim value t = alist(k)         alist(k) = alist(n)         alist(n) = value     loop end sub 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -