News for hackers. Stuff that matters.
Re: by vore on Tuesday May 23, 2023 @12:29AM (#36039837)
This is not a uniform distribution:

  const randIntRange = (i, j, engine = defaultEngine) => {
    const min = Math.ceil(i)
    const max = Math.floor(j)

    return Math.floor(engine() * (max - min + 1)) + min
  }
If you assume engine() outputs, say, 64 bits of entropy, any number range that is not an even factor of 2^64 will exhibit left bias.

The only correct way to do this is to do rejection sampling: generate a number x with log2(max - min) bits and if x >= max - min retry.

Re: by vore on Tuesday May 23, 2023 @02:12AM (#36040539)
Additionally, the shuffle function (sequence.js) has quadratic complexity due to repeated copying of the input array. You could get a vast performance improvement by copying the input array and running the standard Fisher–Yates shuffle over it: it will both run in linear time and will not thrash cache as much.
Re: by chriscavs on Tuesday May 23, 2023 @10:56AM (#36045240)
thanks for bringing this to my attention, I will be sure to check this out
Re: by chriscavs on Tuesday May 23, 2023 @10:52AM (#36045175)
Thank you for the comment! I am aware of this issue, and am working to address in v1.1.0. The context you provide here is very helpful for me. I've opened an issue on github for this: https://github.com/ChrisCavs/aimless.js/issues/2