Hello everybody
I need your help for generating a data in the following format into a text file
the first number in the first bracket denotes the patient and the second number in the first bracket denotes the day.....the number on the right side should be 1 or 100 for a patient on day 1(should be randomly assigned )..if a patient is assigned as 100 on day 1 then he should have 90 on the next day and 80 on the 3rd day and so on. If he is assigned 1 then for all days it is 1.
the number of patients and days should be changeable.....
(1,1) [100]
(1,2) [90]
(2,1) [1]
(2,2) [1]
(3,1) [100]
(3,2) [90]
(4,1) [100]
(4,2) [90]
(5,1) [1]
(5,2) [1]
(6,1) [1]
(6,2) [1]
(7,1) [100]
(7,2) [90]
(8,1) [1]
(8,2) [1]
(9,1) [1]
(9,2) [1]
(10,1)[100]
(10,2) [90] ]
thanks
Bharath
Loading
Kirtan PatelPosted Feb 14, 2010, 12:39 AM
private void btnGenerateData_Click(object sender, EventArgs e)
{
string Result = "";
StreamWriter sw = new StreamWriter("Data.txt", true);
for (int i = 1; i < 100; i++)
{
Random r = new Random();
int day = r.Next(1,4);
int charge =0;
if(day == 1)
{
charge = 100;
}
else if( day==2)
{
charge = 90;
}
else if(day ==3)
{
charge = 80;
}
else if (day == 4)
{
charge = 70;
}
Result = "(" + i.ToString() + "," + day + ")" + "["+ charge.ToString()+ "]";
//Write it to File
sw.WriteLine(Result);
}
sw.Close();
}
bharathwaj vijayakumarPosted Feb 14, 2010, 12:29 PM
In the code that you sent .....days are randomly generated...but the patients and days should be fixed.....only the 1 and 100 should be randomly generated......after that if statements can be written for generating 90, 80 and so on .......
([CODE]
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 2; j++)
{
Random r = new Random();
int pri = r.Next(1, 3);
if (pri == 1)
{
twpriority.Write("\t" + "(" + (i + 1) + "\t");
twpriority.Write((j + 1) + ")");
twpriority.Write("[" + pri + "]");
twpriority.WriteLine("");
}
if (pri != 1)
{
twpriority.Write("\t" + "(" + (i + 1) + "\t");
twpriority.Write((j + 1) + ")");
twpriority.Write("[" + "100" + "]");
twpriority.WriteLine("");
}
}
priority.Clear();
}
twpriority.Close();
twpriority.Close();
[/CODE])
I tried modifying your code.....but it is also generating either 1 or 100 for all the patients....but wat i need is to randomly generate 1 and 100 ......