vendredi 26 mai 2017

How do I write a code for random intervals between a range using numbers in double format?

I am trying to write a program that uses thread.sleep() which only allows integers. My question is how do I create a program that will grab a random number between the range of 2.5-3.5 seconds (or any random range using double) while using all numbers between that range. I am trying to use this to create a randomized auto-clicker for use of understanding of converting these data types. Any help would be appreciated. Thanks!

This is all I have (apologies if this isn't even close I was using all info I could find to help.)

    Robot bot = new Robot();

    int rangeMin=2.5, rangeMax=3.5, pressMax = 0, pressMin = 0;

    int randomvalue1 = (r.nextInt() * ((pressMax - pressMin) + 1)) + pressMin;
    int randomValue2 = (r.nextInt() * ((rangeMax - rangeMin) + 1)) + rangeMax;

    for (int x=0; x<3;x++);
        Thread.sleep(randomvalue1);
        bot.mousePress(InputEvent.BUTTON1_MASK);
        Thread.sleep(randomvalue2);
        bot.mouseRelease(InputEvent.BUTTON1_MASK);
    }




Aucun commentaire:

Enregistrer un commentaire