{
public static string createRandomString(int Length)string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ";Random randNum = new Random();int outputLength = (int)(randNum.NextDouble() * Length); //<<<<<<<<< moved out of loop
char[] chars = new char[outputLength]; //<<<<<<<< use outputLength here
// not used int allowedCharCount = _allowedChars.Length;
{
chars[i] = _allowedChars[(
}
}
for (int i = 0; i < outputLength; i++)int)((_allowedChars.Length) * randNum.NextDouble())];return new string(chars);
Hi,
This code generates same string some time and different string some time
this is random generate code function.
how can i change if i want different string in different length always?
Loading
Sam HobbsPosted Jun 23, 2011, 5:09 PM
VulpesPosted Jun 23, 2011, 9:09 AM
Incidentally, I've assumed that it doesn't matter if there is more than one string with the same length as long as they're unique. If you want the lengths to be unique, then this is easy to adjust for.
anjumathi kumarPosted Jun 23, 2011, 7:23 AM
i want the code in asp.net c#
how can i write the code in asp.net c#
Posted Jun 23, 2011, 6:58 AM
Once the string is genereated from where you're are comparing the newly generated string with the old one. There if the string is already present call the same function again to generate the new one.
Have you tried System.Guid.NewGuid().ToString() ?
Hope you got the idea.
VulpesPosted Jun 23, 2011, 6:58 AM