Fill up string array with random characters?

  • Thread starter Thread starter pedestrian via DotNetMonster.com
  • Start date Start date
P

pedestrian via DotNetMonster.com

Let's say I declares an array of string (of size 1000),
how to fill every elements of it with random characters?

Dim myStrArray(999) As String
...

Thanks...
 
Hello pedestrian via DotNetMonster.com,

Create an array of the characters you want to fill from. Then check out
the Ssytem.Random class.

-Boo
 
Pedestrian, Penang
In addition to the other comments:

How long do you want each string?

How random do you want each string?

To get random "password" keys (WEP Keys) I will use
RNGCryptoServiceProvider.GetNonZeroBytes:

http://msdn2.microsoft.com/en-us/li...rngcryptoserviceprovider.getnonzerobytes.aspx

Followed by BitConverter.ToString:

http://msdn2.microsoft.com/en-us/library/3a733s97.aspx


If you don't want or need a cryptographically strong sequence of values, you
could use System.Random in a loop. Just remember to create the new
System.Random object outside the loop then call its Next method inside the
loop:

http://msdn2.microsoft.com/en-us/library/System.Random.aspx

I would use the Random.Next method that accepted a range of values...
passing in Char code points

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Let's say I declares an array of string (of size 1000),
| how to fill every elements of it with random characters?
|
| Dim myStrArray(999) As String
| ..
|
| Thanks...
|
| --
| Pedestrian, Penang.
|
| Message posted via DotNetMonster.com
| http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-vb-net/200608/1
|
 
Thanks for replying... Mr Jay
I would like to use the strings to insert values to database columns...
such as FirstName, LastName, Address etc.. columns...
Pedestrian, Penang
In addition to the other comments:

How long do you want each string?

How random do you want each string?

To get random "password" keys (WEP Keys) I will use
RNGCryptoServiceProvider.GetNonZeroBytes:

http://msdn2.microsoft.com/en-us/li...rngcryptoserviceprovider.getnonzerobytes.aspx

Followed by BitConverter.ToString:

http://msdn2.microsoft.com/en-us/library/3a733s97.aspx

If you don't want or need a cryptographically strong sequence of values, you
could use System.Random in a loop. Just remember to create the new
System.Random object outside the loop then call its Next method inside the
loop:

http://msdn2.microsoft.com/en-us/library/System.Random.aspx

I would use the Random.Next method that accepted a range of values...
passing in Char code points

| Let's say I declares an array of string (of size 1000),
| how to fill every elements of it with random characters?
[quoted text clipped - 3 lines]
|
| Thanks...
 
Back
Top