0

I was making a button move by the click of it, and heres my code:

button1.location = new Point(new Random().Next(10, 385), new Random().Next(10, 385));

But that only seems to move the button in a diagonal line. Please help. Thanks

user2997877
  • 65
  • 2
  • 9
  • `r = new Random();. ...location = new Point(r.next(10,385), r.next(10,385))`. use a SINGLE random object – Marc B Nov 27 '13 at 21:06

1 Answers1

6

Two Randoms created in a very short time (like in your code) will return a deterministic value. This is because in that time the seed values will not differ.

You should create a Random before and reuse it:

var random = new Random();
button1.location = new Point(random.Next(10, 385), random.Next(10, 385));