mercredi 17 juin 2020

Weighted randomness based on current values (Not sure how else to explain it)

Need some help with some code (Java)

I have a script which runs every few mins This script creates and deletes objects

For the sake of this example I want to have an average of 10 objects at any time

But a random probability of it creating and deleting objects based on how far it is from that 10 goal with hard limits, eg +- 3

I have gotten it to create objects till it reaches 7, and then delete once it goes past 13 But I cant figure out how to do the randomness between

If there is say 8 objects then it would have a higher probability of creating rather than deleting, if there are 10 then its a 50/50 split and if there is 12 then its more likely to delete then create

and im not asking for code, im happy to figure that out myself I just need a push in the right direction

Edit for update with what I currently have, I dont have the full code as there is alot of other things going on, but this is the part i need help with

This runs every min

int limit = F_Config.get().getInt("Limit");
int avg = F_Config.get().getInt("Average");
int current = P_Player.ReturnList().size();
int min = avg - limit;
int max = avg + limit;

//below min
if(current < min) {
    Main.sendConsole("Min");
    P_Player.LoginPlayer();
}

//above Max
else if(current > max) {
    Main.sendConsole("Max");
    P_Player.LogoutPlayer();
}

//Between min and Max
else{
    //Stuff here
}



Aucun commentaire:

Enregistrer un commentaire