对啦!这里有个游戏开发交流小组里面聚集了一帮热爱学习unity的零基础小白,也有一些正在从事unity开发的技术大佬,欢迎你来交流学习。
洗牌代码//Fisher-Yates shuffle
static void Shuffle(T[] array)
{
int n = array.Length;
for (int i = 0; i < n; i++)
{
int r = i + Random.Range(0, n - i);
T t = array[r];
array[r] = array[i];
array[i] = t;
}
}
带权重随机代码static public int GetRandomWeightedIndex(float[] weights)
{
// Get the total sum of all the weights.
float weightSum = 0;
for (int i = 0; i < weights.Length; ++i)
{
weightSum += weights[i];
}
// Step through all the possibilities, one by one, checking to see if each one is selected.
int index = 0;
int lastIndex = weights.Length - 1;
while (index < lastIndex)
{
// Do a probability check with a likelihood of weights[index] / weightSum.
if (Random.Range(0, weightSum) < weights[index])
{
return index;
}
// Remove the last item from the sum of total untested weights and try again.
weightSum -= weights[index++];
}
// No other item was selected, so return very last index.
return index;
}
伪随机C系数生成代码static public float CfromP(float p)
{
float Cupper = p;
float Clower = 0f;
float Cmid;
float p1;
float p2 = 1f;
while (true)
{
Cmid = (Cupper + Clower) / 2f;
p1 = PfromC(Cmid);
if (Mathf.Abs(p1 - p2) p)
{
Cupper = Cmid;
}
else
{
Clower = Cmid;
}
p2 = p1;
}
return Cmid;
}
private float PfromC(float C)
{
float pProcOnN = 0f;
float pProcByN = 0f;
float sumNpProcOnN = 0f;
int maxFails = Mathf.CeilToInt(1f / C);
for (int N = 1; N
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?