vendredi 30 août 2019

Create a random, but most frequently in a certain range

I have to create a certain task that simulates the systolic pressure of a person, so i tried this:

rand = new Random();
timer = new Timer();
timer.schedule(new TimerTask() {

@Override
public void run() {
    Integer sbp = rand.nextInt((130 - 80) + 1) + 80;
        lblSBPCounter.setText(Integer.toString(sbp));           
}
}, 1000, 120000);

The problem is that the systolic pressure has a range from 90 to 120. If it goes below 90 or above 120, that person is in trouble. So in the code i tried to generate a random number every 2 minutes from 80 to 130. The problem is that the random function goes pretty often under and above the range. So my question is: Can i make the function generate more numbers from 90 to 120 and less numbers under 90 and above 120? Like 1 number every 1-2 hours?




Aucun commentaire:

Enregistrer un commentaire