parmentf/random-weighted-choice

An item with a little floating point weight, alone, is not chosen

parmentf opened this issue · 1 comments

Example at https://github.com/parmentf/ector-monorepo/blob/35bbaf4358e12545e3b6dc61fb5e8636fb4f4518/packages/core/src/core.js#L257-L259

const chosenItem = rwc(previousNodes, temperature);
const chosenItemIndex = getNodeIndex(cn, chosenItem);
const chosenTokenNode = { id: cn.node[chosenItemIndex].label, weight: -1 };

Where the resulting variables are:

{
  "chosenItemIndex": -1,
  "chosenItem": null,
  "temperature": 60,
  "previousNodes": [ { "id": "wje", "weight": 0.07692307692307693 } ]
}

Version 0.1.4 fix it.