0

I've been working on a program using the Java Robot class to move my mouse to a random location bound between an area of pixels. As some of you know, the moveMouse method works as moveMove(x,y) where x is the horizontal pixel number and y is the vertical pixel number. I would then math a random number generator using math.random to have the program click on a random pixel in a rectangular section on my screen. this line would look like this (the numbers are arbitrary values)

robot.mouseMove(randomNum(350,400),randomNum(350,400)

Where it would pick between pixels 350-400 on the x direction. and 350-400 in the y direction. Although, the problem I am running into is that eventually after a few hundred-1000 iterations, the scattermap of clicks looks... not so random:

"random" clicks

So I thought I would solve this problem by then adding 2 arrays that hold the pixel values for the corresponding x and y values that I want, and add weighted RNG by repeating pixel numbers so it would have a higher chance of going to those pixels. But I still end up with an unnatural looking scatter chart. Here is my code:

private static int[] items = new int[] 
{/*insert x coord pixels*/ };
    private static Random rand = new 
Random();

    public static int getRandArrayElement() 
 {
        return 
 items[rand.nextInt(items.length)];
    }


    private static int[] items2 = new int[] 
{/*insery y coord pixels*/};
    private static Random rand2 = new 
Random();

    public static int 
getRandArrayElement2(){
        return 
items2[rand2.nextInt(items2.length)];
    } 



robot.mouseMove(getRandArrayElement(),getRandArrayElement2());
robot.mousePress(button);
robot.delay(randomNum(11,32));
robot.mouseRelease(button);
robot.delay(randomNum(11,32));

This code still has the same constraint as the last, no matter what, my scatter plot still will resemble a rectangle of some kind. Is there any way I can make a list, where each value has a readable x AND y value, so I can hard code weighted RNG by omitting certain pixels so I can choose what shape the scatter plot will resemble? I'd like to make it look more like this:

More random looking click plot

So if anyone has any helpful info that they'd like to share, I'm all ears. cheers. :)

luator
  • 4,769
  • 3
  • 30
  • 51
  • Some examples using random data with [tag:jfreechart] are seen [here](https://stackoverflow.com/search?tab=votes&q=user%3a230513%20%5bjfreechart%5d%20ChartFactory.createScatterPlot). – trashgod Dec 09 '18 at 03:32
  • What is jfreechart? do you think that would be applicable to this? – old school Dec 09 '18 at 03:43
  • I don't know about your use case; it's a convenient way to experiment with various [distributions](https://commons.apache.org/proper/commons-math/userguide/distribution.html). – trashgod Dec 09 '18 at 12:05
  • Both of those suggestions are good thoughts, but I'd like to make one list that contains numbers that the mouseMove(x,y) function can take from. for example, if i had a 4x4 box of pixels, and made the array filled with [1,2,3,4....16], the mouseMove function can take one of those points and know to go to that singular pixel. – old school Dec 10 '18 at 18:48
  • In this [example](https://stackoverflow.com/a/20359200/230513), `createSampleData()` fills an `XYSeries` with data having a Gaussian distribution in both dimensions; the other examples are similar. – trashgod Dec 10 '18 at 23:22
  • Thanks for that, but is there a way I can do that but have it actually click my screen in that manner, and not fill in a chart? – old school Dec 11 '18 at 01:31
  • You could fill your array(s) in a similar way. – trashgod Dec 11 '18 at 09:27

0 Answers0