J Juan Aug 27, 2005 #1 Hi How to generate an unique random string of determinate characters length? Thanks
G Guest Aug 27, 2005 #2 Hi Juan, one way you could do this is shown below. The code creates a string of pre-determined length that consists only of the character A-Z: int stringLength = 10; Random rnd = new Random((int)System.DateTime.Now.Ticks); System.Text.StringBuilder randomText = new System.Text.StringBuilder(stringLength); //value of A in ascii codes int minValue = 65; //value of Z in ascii codes int maxValue = 90; //the range that we are allowed to go above the min value int randomRange = maxValue - minValue; double rndValue; for(int i=0; i<stringLength; i++) { rndValue = rnd.NextDouble(); randomText.Append((char)(minValue + rndValue * randomRange)); } Console.WriteLine(randomText.ToString()); Hope that helps Mark R Dawson
Hi Juan, one way you could do this is shown below. The code creates a string of pre-determined length that consists only of the character A-Z: int stringLength = 10; Random rnd = new Random((int)System.DateTime.Now.Ticks); System.Text.StringBuilder randomText = new System.Text.StringBuilder(stringLength); //value of A in ascii codes int minValue = 65; //value of Z in ascii codes int maxValue = 90; //the range that we are allowed to go above the min value int randomRange = maxValue - minValue; double rndValue; for(int i=0; i<stringLength; i++) { rndValue = rnd.NextDouble(); randomText.Append((char)(minValue + rndValue * randomRange)); } Console.WriteLine(randomText.ToString()); Hope that helps Mark R Dawson
O Octavio Hernandez Aug 27, 2005 #3 If developing an ASP.NET application, you might find useful the SessionId property, http://msdn.microsoft.com/library/d...nStateHttpSessionStateClassSessionIDTopic.asp a string that uniquely identifies each session. Regards - Octavio
If developing an ASP.NET application, you might find useful the SessionId property, http://msdn.microsoft.com/library/d...nStateHttpSessionStateClassSessionIDTopic.asp a string that uniquely identifies each session. Regards - Octavio