mardi 24 juillet 2018

Loop a function every random seconds, with a random delay and more (specific, read)

Sorry for being a burden but I am very new to Java and programming in general. I have attempted to solve my problem by using the searchbar but that has only brought more confusion. I only know the bare minimum to use Java, so this is taking way longer than it should.

To get to the point: Basically what I want to be accomplished is a function that will generate a random integer within the range 85-10. Then after a random amount of time (1-25 seconds), that number will get subtracted by another random integer in the range of 0-3 and call another function. Once the first random integer is less than 4, wait a random amount of time and then restart the loop

here is my psuedocode: (my java is ugly and doesn't work yet lol)

loop() {                                                       //main loop
    int count = 85+(int)(Math.random()*((100-85)+1));           //randint range 85-100
    for count in range(4, 101) {                               //loop until count is too low
        int lossage = (int)(Math.random()*3);                  //randint to determine lossage
        Sleep(1000+(int)(Math.random()*((25000-1000)+1)));     //wait 1-25 seconds
        int result = count - lossage;                          //calculate count after loss
        OtherFunction();                                       //call other function
        Sleep(1000+(int)(Math.random()*((5000-1000)+1)));      //wait 1-5 seconds 
    }                                                          //loop again
    else {                                                     //case if count is too low
        Sleep((1+(int)(Math.random()*((20000-10000)+1)));      //wait 10-20 seconds to restart
}

If somebody can convert this to working Java and explain how it works I would be infinitely grateful. I have been trying for an hour to get this too work. Conditional loops confuse me, maybe I am missing something obvious. Thanks




Aucun commentaire:

Enregistrer un commentaire