Skip to content

weightedPick() looks biased #6562

@samme

Description

@samme

Version

  • Phaser Version: 3.0.0 to 3.60.0

Description

shy and wayfinder reported/tested this on Discord.

It looks like weightedPick() undersamples the first and last array members.

Log-linear plot of weightedPick distribution

Example Test Code

https://codepen.io/samme/pen/qBQKYxN?editors=0110

Additional Information

I think it's supposed to be

return array[~~(Math.pow(this.frac(), 2) * array.length)];

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions