title: Creating a secure random password generator in VB.Net
body: <p>I'm trying to create a secure random password generator as a little project to teach myself VB.Net, and I came across the following <a href="http://www.codeguru.com/csharp/csharp/cs_misc/security/article.php/c14557/Cryptographically-Random-Password-Generator.htm" rel="nofollow">article</a> for C#.</p>
  
  <p>After trying to convert it into VB.Net, my program just spits out a string of "0" of varying length depending on my combobox selection.</p>
  
  <p>I'd like to understand what I've done wrong, as it's a learning experience for me, so any help would be greatly appreciated.</p>
  
  <pre><code>Imports System.Security.Cryptography
  Imports System.Text
  
  Public Class Form1
      Dim randomBytes() As Byte
      Dim randomInt32Value As Integer
      Dim possibleChars As String
  
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          System.Security.Cryptography.RandomNumberGenerator.Create.GetBytes(randomBytes)
          randomInt32Value = BitConverter.ToInt32(randomBytes, 0)
      End Sub
  
      Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
          Dim builder As New StringBuilder
  
          For value1 As Integer = 0 To ComboBox1.SelectedIndex
              Dim r = New Random(randomInt32Value)
              possibleChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&amp;*()"
              Dim nextInt As Integer = r.Next(possibleChars.Length)
              Dim c As Char = possibleChars(nextInt)
              builder.Append(c)
          Next
  
          Label1.Text = builder.ToString()
      End Sub
  End Class
  </code></pre>