This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
export function randomPointInCircle(origin, radiusPx) {
|
||||
const angle = Math.random() * Math.PI * 2;
|
||||
const distance = Math.sqrt(Math.random()) * radiusPx;
|
||||
const angle = randomUnitFloat() * Math.PI * 2;
|
||||
const distance = Math.sqrt(randomUnitFloat()) * radiusPx;
|
||||
|
||||
return {
|
||||
x: origin.x + Math.cos(angle) * distance,
|
||||
@@ -19,3 +19,14 @@ export function sceneDistanceToPixels(distance) {
|
||||
const distancePerGrid = canvas.scene.grid.distance || 5;
|
||||
return distance / distancePerGrid * gridSize;
|
||||
}
|
||||
|
||||
function randomUnitFloat() {
|
||||
const cryptoApi = globalThis.crypto;
|
||||
if (!cryptoApi?.getRandomValues) {
|
||||
throw new Error("A cryptographically secure random generator is not available.");
|
||||
}
|
||||
|
||||
const values = new Uint32Array(1);
|
||||
cryptoApi.getRandomValues(values);
|
||||
return values[0] / 0x100000000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user