C
cvnweb
I am trying to generate 2 random numbers that are diffrent, in order to
add them to existing numbers to generate numbers that start out the
same, but are randomly added and subtracted so that they can go down
similar paths, but not be the same. I will implement code later to make
sure i they go more than 10 apart from each other that they are moved
closer together, but this is what I have so far, and when the program
is run, the two random numbers (RA, RB) end up being the same,
resulting in these 2 numbers always being Identicle, how can I prevent
this?
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
int X=0;
int Y=0;
private void button1_Click(object sender, System.EventArgs e)
{
int RA=RandomNumber(-3,4);
int RB=RandomNumber(-2,5)-1;
X=X+RA;
Y=Y+RB;
if (X<=0 && Y<=0)
{
X=0;
Y=0;
}
else if (Y<=0)
{
Y=0;
}
else if (X<=0)
{
X=0;
}
lblA.Text=X.ToString();
lblB.Text=Y.ToString();
}
add them to existing numbers to generate numbers that start out the
same, but are randomly added and subtracted so that they can go down
similar paths, but not be the same. I will implement code later to make
sure i they go more than 10 apart from each other that they are moved
closer together, but this is what I have so far, and when the program
is run, the two random numbers (RA, RB) end up being the same,
resulting in these 2 numbers always being Identicle, how can I prevent
this?
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
int X=0;
int Y=0;
private void button1_Click(object sender, System.EventArgs e)
{
int RA=RandomNumber(-3,4);
int RB=RandomNumber(-2,5)-1;
X=X+RA;
Y=Y+RB;
if (X<=0 && Y<=0)
{
X=0;
Y=0;
}
else if (Y<=0)
{
Y=0;
}
else if (X<=0)
{
X=0;
}
lblA.Text=X.ToString();
lblB.Text=Y.ToString();
}