المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Random Selection



C# Programming
07-20-2012, 03:02 AM
Hi all, I am trying to randomly select a character set from a list to be used in my function but I can't get it to work, below is what I have thus far.

public const string myChars1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const string myChars2 = "abcdefghijklmnopqrstuvwxyz";
public const string myChars3 = "0123456789";

private string RandomString()
{

char[] buffer = new char[24];
int i = 0;
while (i < 23)
{
int k = 0;
string S = "";
Random myRandomNum = new Random();
Random myRandomNum2 = new Random();
k= myRandNum2.Next(1,3);
S = Convert.ToChar(k);
buffer[i] = myChars+S[myRandNum.Next(myChars+S.Length)];
i++;

}
return new string(buffer);
}
I am trying to tack S to the end of myChars so that I will get myChars1, myChars2, or myChars3 randomly but it's not working. How could I achieve this? Any suggestions is greatly appreciated, thanks in advance for your help.