Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,955 questions

51,897 answers

573 users

How to generate random string in VB.NET

2 Answers

0 votes
Imports System
 
Public Class program
	Public Shared Function generate_random_string(size As Integer) As String
 		Dim rnd As New Random
		
        Dim characters As String = "0123456789" +
                                   "abcdefghijklmnopqrstuvwxyz" +
                                   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
        Dim rs As New System.Text.StringBuilder
 
        For ct As Integer = 1 To size
            rs.Append(characters(rnd.Next(0, characters.Length)))
        Next

        Return rs.ToString
 
    End Function
 
    Public Shared Sub Main(ByVal args As String())
        Console.WriteLine(generate_random_string(10))
    End Sub
End Class


 
' run:
' 
' cA5xtozQka
'

 



answered Apr 6, 2016 by avibootz
edited Apr 15, 2024 by avibootz
0 votes
Imports System
Imports System.Text
  
Public Class Program
    Public Shared Function generateRandomString(ByVal len As Integer) As String
        Dim charset As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
        Dim rnd As Random = New Random()
        Dim sb As StringBuilder = New StringBuilder(len)
  
        For i As Integer = 0 To len - 1
            sb.Append(charset(rnd.[Next](charset.Length)))
        Next
  
        Return sb.ToString()
    End Function
  
    Public Shared Sub Main()
        Console.Write(generateRandomString(10))
    End Sub
End Class
  
  
  
' run:
'
' oBKtgMAnwF
'

 



answered Apr 15, 2024 by avibootz
...