vb.net - Key gen random number issue -


i in need of random number generator in following format: 65x xxx xxxx ; excluding 1 & 4. final step before im finished first vb.net project. please respond if can help.

below currant code works great other not excluding digits. if please edit code ever grateful.. thank you!

private sub timer1_tick(byval sender system.object, byval e system.eventargs) handles timer1.tick  dim rnd new random dim str1, str2, str3 string str1 = "65" & rnd.next(0, 9) str2 = rnd.next(100, 999) str3 = rnd.next(1000, 9999) listbox1.items.add(str1 & " " & str2 & " " & str3) end sub 

create 1 random generator instead of creating new 1 on each timer click. random generator seeded value created system clock, if create them close in time generate same series of random numbers. also, creating them @ set interval might produce unwanted patterns in random numbers.

private rnd new random 

you can use function creates random string specific set of characters:

private function randomstring(byval chars string, byval len integer) string   dim result string = ""   integer = 1 len     result += chars.substring(rnd.next(chars.length), 1)   next   return result end function 

(note: using += concatenate strings should used short strings. longer 20 characters should use stringbuilder or character array instead.)

now can use function create string:

private sub timer1_tick(byval sender system.object, byval e system.eventargs) handles timer1.tick   dim chars string = "02356789"   dim str string = "65" & _     randomstring(chars, 1) & " " & _     randomstring(chars, 3) & " " & _     randomstring(chars, 4)   listbox1.items.add(str) end sub 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -