Created
January 12, 2023 07:37
-
-
Save framp/70ef9a018df07e83e0b7254ef1581d14 to your computer and use it in GitHub Desktop.
Newton-Rhapson-Method for nicely distributed random numbers on a 2d plane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomPoints = (n: number, d = 2) => | |
const d = 2; | |
let g = 1.0; | |
for (let i = 0; i < 20; i++) { | |
g = g - (Math.pow(g, d + 1) - g - 1) / ((d + 1) * Math.pow(g, d) - 1); | |
} | |
const alpha = new Array(d).fill(0); | |
for (let j = 0; j < d; j++) { | |
alpha[j] = Math.pow(1 / g, j + 1) % 1; | |
} | |
const points = new Array(n).fill(0).map(() => new Array(d).fill(0)); | |
for (let i = 0; i < n; i++) { | |
for (let j = 0; j < d; j++) { | |
points[i][j] = (0.5 + alpha[j] * (i + 1)) % 1; | |
} | |
} | |
return points; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment