求生成圆内均匀随机点的最佳实践

我知道这样随机:

randomInsideCircle(radius): { x: number, y: number } {
    let theta = Math.random() * Math.PI * 2;
    let x = Math.cos(theta) * radius * Math.random();
    let y = Math.cos(theta) * radius * Math.random();
    return { x, y };
}

但似乎接近内部的概率会偏大。
改进的思路是把上面的radius放到 类似 EaseOut函数 里面做个变换。但具体用什么函数我不太清楚。EaseOut是可以把原值更变换到更接近1,更靠近外侧的位置。这只是个定性的感觉。

randomInsideCircle(radius, f: (x: number) => number = x => x): { x: number, y: number } {
    let theta = Math.random() * Math.PI * 2;
    let r01 = f(Math.random());
    let x = Math.cos(theta) * r01 * radius;
    let y = Math.sin(theta) * r01 * radius;
    return { x, y };
}

参数使用x => 1 - Math.pow(1 - x, 3),类似EaseOut。因为是类似爆碎片的特效,希望大多数更靠近外侧。美术也不是数学,现在是差不多得了。

还有个思路是只管生成在正方形内,检查后再把圆外的剔除,会出现废弃操作,内心不怎么喜欢。

另外发现Unity有个random.insideUnitCircle,不知里面如何实现的。
那有没有均匀随机的思路呢?

1赞