vb.net - New Random in a For-Next-Statement Repeats the Same Value -
i creating 3 random bytes in for-next-statement.
however, same each for-next, example "333", or "777".
i wonder why , doing wrong.
private sub button1_click(sender object, e eventargs) handles button1.click dim s string = string.empty integer = 0 2 s += getrandombyte().tostring next me.textbox1.text = s end sub public function getrandombyte(optional byval ulow byte = 1, optional byval uhigh byte = 9) byte dim r new random dim b integer = r.next(cint(ulow), cint(uhigh + 1)) return b end function
in constructor new random, give new seed each time. use current timestamp's hashcode value
new random(now.gethashcode)
Comments
Post a Comment