How to get a random value using the RANDOM class in C#

Karthikanbarasan
Posted by Karthikanbarasan under C# category on | Points: 40 | Views : 1565
const int MAXVAL = 45;
const int MAXELEMENTS = 80;
static string stringHash = "##################################################################";
int[] intdata = new int[MAXELEMENTS];

private void Button_Click(object sender, EventArgs e)
{
int i;
string strbuffer;
Random rd = new Random(5);
lstViewResult.Items.Clear();
for (i = 0; i < data.Length; i++)
{
intdata[i] = rd.Next(MAXVAL);
strbuffer = intdata[i].ToString() + " " + stringHash.Substring(0, intdata[i]);
lstViewResult.Items.Add(strbuffer);
}
}

Comments or Responses

Login to post response