【发布时间】:2020-03-05 09:24:50
【问题描述】:
下面函数的目的是使用种子 - rnd[] 生成一个随机数数组,下面的查找是查找与给定坐标关联的随机数的快速方法。似乎此函数将 3D 空间中的任何坐标 (x,y,z) 转换为 8192 的固定长度数组的索引。我不确定该函数是否准确,我认为它是准确的,但我想使用比下面更大的数组。我觉得它不够随机,只有 8192 个随机数可供使用。
如何更改代码以使用长度为 262144 而不是 8192 的数组?
public static float GetValue(Vector3 position) {
long hash = 17 * 23 + (long)position.x;
hash = hash * 23 + (long)position.y;
hash = hash * 23 + (long)position.z;
hash += (hash >> 26) + (hash >> 13);
rndIndex = (uint)(hash & 8191);
return (float)rnd[rndIndex];
}
【问题讨论】: