0

Sorry for my poor English.

I just curious if does the Random alphanumeric is very unique even i have a millions of data? Because I develop a software that I want every data have a unique Alphanumeric.

By the way, how many sets of random does this code make?

Dim s As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Dim r As New Random
Dim sb As New StringBuilder

For i As Integer = 1 To 8
    Dim idx As Integer = r.Next(0, 35)
    sb.Append(s.Substring(idx, 1))
Next

random.Text = sb.ToString()
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • Random does not mean unique. Things do repeat in random sets of data even when the set it large. You'll need to explain *what* you are trying to do to get much help. – Ňɏssa Pøngjǣrdenlarp Oct 22 '16 at 20:00
  • Do you mean http://stackoverflow.com/q/3034861/11683 or the sort? – GSerg Oct 22 '16 at 20:01
  • I'm sorry. What I want to know is every set of random is it unique? and how many possibilities does it can make? thank you @Plutonix – Yevrah Aradnop Oct 22 '16 at 20:02
  • @GSerg I'm a newbie in vb.net. I want to know what the snippets. Thank You. – Yevrah Aradnop Oct 22 '16 at 20:04
  • I still don't know what you want to do. I assumed you want to generate a lot of unique strings, like Youtube does for the video ids. If that is so, please click the link and follow from there. Otherwise please explain what you want to do. – GSerg Oct 22 '16 at 20:11
  • 1
    That's simple combination calculation : with the sample it gives `C(36, 8) = 30260340` – Sehnsucht Oct 22 '16 at 20:16
  • You can immediately know how many because it's a [well known formula](https://en.wikipedia.org/wiki/Permutation#k-permutations_of_n). And if you need to actually generate them all, see various question that you can find by the keyword "permutation", such as http://stackoverflow.com/q/21840430/11683 or http://stackoverflow.com/q/9976215/11683. – GSerg Oct 22 '16 at 20:18
  • Can you show me how to make maybe billion sets of random alphanumeric? @Sehnsucht – Yevrah Aradnop Oct 22 '16 at 20:20
  • 1
    @YevrahAradnop there is maybe no need to ; depending on what you need with the current parameters ("alphabet" and length) there are `30260340` combination but there are also `2821109907456` permutation with repetition (36 ^ 8) as linked by @GSerg – Sehnsucht Oct 22 '16 at 20:25

0 Answers0