You need to move the Random instance outside of your method, into a static
field. Random's constructor, when called, initializes using the time as a
seed value for the pseudo-random generator and so multiple calls may provide
the same tick of time as the seed, causing the first value to be the same.
Richard
--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Maziar Aflatoun" <(E-Mail Removed)> wrote in message
news:QBNJb.123684$(E-Mail Removed)...
> Hi everyone,
>
> I have the following random string generator
>
> public static string getAlphabets(int strLength)
> {
> string RandomString = "";
> Random X = new Random();
> for (int x=0; x < strLength; x++) RandomString +=(char)(X.Next(65,
90));
> return RandomString;
> }
>
> The only problem is that it returnsthe extact same randomly generated
string
> when called more than one times. Any idea?
>
> Tank you
> Maz A.
>
>