0

I designed the values to fit to an off-center bell-curve. Trial runs seem to give desirable results, but is there anything I am missing?

What I have discovered

I found a question that thought would help, but they are using standard deviation.

JavaScript Math.random Normal distribution (Gaussian bell curve)?

From the question above:

  • Q: Is Math.random already normally-distributed?
  • A: No

What I have

const ranks = [
  ['X'   , 0.01, 0.01],
  ['SSS' , 0.03, 0.04],
  ['SS'  , 0.06, 0.10],
  ['S'   , 0.08, 0.18],
  ['A'   , 0.11, 0.29],
  ['B'   , 0.14, 0.43],
  ['C'   , 0.21, 0.64],
  ['D'   , 0.17, 0.81],
  ['E'   , 0.12, 0.93],
  ['F'   , 0.07, 1.00]
];

log('Total:', ranks.reduce((a, b) => a + b[1], 0).toFixed(2));
for (let i = 0; i < 10; i++) {
  generate();
}

/* Public */
function generate() {
  let percent = Math.random();
  log(percent.toFixed(4), getRank(percent));
}

/* Protected */
function getRank(percent) {
  return ranks.filter((rank, index) => {
    let min = index > 0 ? ranks[index - 1][2] : -1;
    return percent > min && percent <= rank[2];
  })[0][0];
}

/* Private */
function log() {
  let el = document.createElement('DIV');
  el.innerHTML = [].slice.call(arguments).join(' ');
  el.className = 'log-line';
  document.body.appendChild(el);
}
body {
  background: #666;
}

.log-line {
  font-family: monospace;
  background: #AAA;
  margin: 0.5em 0.25em;
  padding: 0.25em;
}

.log-line::before {
  content: '>>> ';
}

enter image description here

Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • What do you want to achieve? Do you want to find the weights to use for each rank given a custom distribution with user-specified parameters (e.g., mean and standard deviation)? – Peter O. Apr 25 '19 at 01:39
  • @PeterO.I want to generate a random number that can fall within those ranges. The mean in this case is C. Could I fit this to an asymmetrical bell curve? [Like the green line in the 2nd figure](https://thecuriousastronomer.wordpress.com/2014/06/26/what-does-a-1-sigma-3-sigma-or-5-sigma-detection-mean/). – Mr. Polywhirl Apr 25 '19 at 02:03

1 Answers1

0

What you may be missing is the following:

  • Assign each rank ("X", "SS", etc.) to a point on the number line.
  • For each rank, calculate the normal distribution's PDF (probability density function) at that point (using a custom mean and standard deviation). This is the probability for that rank.
  • Given the implementation here: Divide the probability for each rank by the sum of all probabilities.
  • Given the implementation here: Calculate the cumulative probabilities.

The last two steps are not strictly necessary if you use an implementation of weighted random selection that—

  • allows the probabilities to sum to other than 1, and
  • calculates cumulative probabilities "on the fly".
Peter O.
  • 32,158
  • 14
  • 82
  • 96
  • I was thinking that if each rank was a percentage of 100, would that equate to rolling _n_-number of dice, which each rank having _m_-faces and summing up the total (weighed of course)? – Mr. Polywhirl Apr 25 '19 at 02:30