What should be written in order to randomize movement of a picturebox ?

If i want to make a picturebox move either to the left by 3 pixels or more wot should i write
Is there an appropriate random function


Answer this question

What should be written in order to randomize movement of a picturebox ?

  • Badekapp

    When it comes to generating random numbers, look no farther than the Random class (System.Random).

    To create an instance (with a changing seed value to ensure more randomness), we simply instantiate a copy:

    Random rand = new Random(DateTime.Now.Millisecond);

    To get a random integer value you need only call the Next() method, and to specify upper and lower bounds, just pass them in as arguments:

    rand.Next(1,3);

    When moving the PictureBox either right or left, its up to you how you decide which way to go, however a simple way would be to generate a random number between say 0 and 1 and move the PictureBox left when you get 0 and right when you get 1.

    Does this answer your question



  • tamlin2

    I just do:

    Point rndPoint = new Point(Int.parse(new Random().Next(3), new Random().Next(3));

    pictureBox.Location = rndPoint;


  • What should be written in order to randomize movement of a picturebox ?