ianfhunter / GNOLL

GNOLL is an efficient dice notation parser for multiple programming languages that supports a wide set of dice notation
https://www.ianhunter.ie/GNOLL/
GNU General Public License v3.0
39 stars 23 forks source link

Experimental Optimization: CLT/Box-Muller #391

Closed ianfhunter closed 1 year ago

ianfhunter commented 1 year ago

Using the central limit theorom, as the number of dice rolled grows, the closer they resemble a normalized distribution curve.

We introduced a new function that allows us to roll on a normal distribution and received distributions, though they trend less centrally than the original: Pasted image 20221128154954 Pasted image 20221128154732

This optimization allows us to roll once on the normalized random generation, rather than N times on the uniform random generation.

This is slower than the uniform randomness at low frequencies, but at higher frequencies we get a near constant runtime instead of the old version which scales with number of dice.

Warning: There is one major drawback to this approach in that it completely collapses the dice pool, so operations such as dropping/keeping/introspection cannot be performed on the result.

Pasted image 20221128180050

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication