Sam Anders

Sam Anders

  • NA
  • 3
  • 2.3k

Help with generating random numbers.

Aug 8 2011 8:38 PM
Help! im trying to generate a random number for a very basic XNA application I have been working on. Right now, what im trying to do is have an image display at a random co-ordinate at the screen. I've been successful at getting the circle to appear at a random point, the problem is; I can't get it to stop being at a random point! Literally all it does is bounce around the screen like it's high on crack. I would like to know how to generate a single random number for X/Y values and then stop. If anyone could help me with this it would be much appreciated.
//the draw function
        {
            graphics.GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();
            spriteBatch.Draw (circle, new Rectangle(circlePosY + 180, circlePosX + 180, circle.Height, circle.Width), Color.White);
            spriteBatch.Draw(circleG, new Rectangle(0, 0, circleG.Height, circleG.Width), Color.White);
            spriteBatch.End();
            GPosResultX = rand.Next(1,380);
            GPosResultY = rand.Next(1, 380);

        }

//definitions
    int circleGPosY;
        int circleGPosX;
        int GPosResultX;
        int GPosResultY;
        Random rand = new Random();



Answers (2)