B
bitshift
Anyone got an example ?
bitshift said:Anyone got an example ?
Anyone got an example ?
bitshift said:Anyone got an example ?
Jon said:1) Hard-code a string with all the characters you want to include
2) Use a single instance of Random (with appropriate locking if you're
going to use it from many threads)
3) Create a StringBuilder of the right length
4) In a for loop, append the next random character by using
Random.Next, passing in the string's length, and using string's
indexer
5) Call ToString on the StringBuilder
Jon
Two questions:Anyone got an example ?
bitshift said:Anyone got an example ?
Peter said:char[] chars = new char[62];
chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
Arne Vajhøj said:Peter said:char[] chars = new char[62];
chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
Why the new char[62] ?
Arne
Arne Vajhøj said:Peter said:char[] chars = new char[62];
chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
Why the new char[62] ?
Arne
I suppose you could do it this way if you prefer:
char[] chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
Peter said:whoops, my bad. There are indeed 62 characters in the string.Arne Vajhøj said:Why the new char[62] ?Peter said:char[] chars = new char[62];
chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();