mardi 21 janvier 2020

Chance of obtaining fish element Probability

I'm trying to get the percentage of getting some fish. X is the unique number here, it's between 0-99, but in my example code it's 70, for test purposes.

But currently it returns really wrong results, so I'm doing something wrong here.

Current output:

[-0.17142857142857143, 0.04285714285714286, 0.2571428571428571, 0.2714285714285714]

Which means

  • -17% to get fish1,
  • 4.2% for fish2,
  • 25.7% fish3,
  • 27% fish4.

The correct math is as follows:

If X number is 82+, it will get fish 1. If X number is 67+, it's fish 2 (unless 82+ etc). If x number is 52+ it's fish 3. if it's 51 or less, it's fish 4.

So, in theory, with a x of 85, its a 3/85 chance of obtaining it.

Then I need the probability by the current X of getting that specific fish. What am I doing wrong here?

function fishesPercentage(X) {
  var NumberSelected = RandomNumber(0,X-1);
  NumberSelected = 70;
  console.log("RANDOOM NUMBER IS : ",NumberSelected);
  let Fish1 = NumberSelected - 82;
  let Fish2 = NumberSelected - 67;
  let Fish3 = NumberSelected - 52;
  let Fish4 = NumberSelected - 51;

  return [
    Fish1/ NumberSelected,
    Fish2/ NumberSelected,
    Fish3/ NumberSelected,
    Fish4/ NumberSelected
  ];
}



Aucun commentaire:

Enregistrer un commentaire