By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Generate Unique Random String

P: n/a
Hi
How to generate an unique random string of determinate characters length?

Thanks
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"Juan" wrote:
Hi
How to generate an unique random string of determinate characters length?

Thanks

Nov 17 '05 #2

P: n/a

If developing an ASP.NET application, you might find useful the SessionId
property,

http://msdn.microsoft.com/library/de...ionIDTopic.asp

a string that uniquely identifies each session.

Regards - Octavio

"Juan" <no@spam.com> escribió en el mensaje
news:ej**************@TK2MSFTNGP10.phx.gbl...
Hi
How to generate an unique random string of determinate characters length?

Thanks

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.