浏览代码

Added SamplerUtility.Hash32NonZero() API

/main
Steven Leal 4 年前
当前提交
a2571f97
共有 3 个文件被更改,包括 16 次插入3 次删除
  1. 5
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
  2. 12
      com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
  3. 2
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs

5
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs


/// <returns>The generated sample</returns>
public float Sample()
{
var rng = new Unity.Mathematics.Random(ScenarioBase.activeScenario.NextRandomState());
return math.lerp(range.minimum, range.maximum, rng.NextFloat());
var newRandomState = ScenarioBase.activeScenario.NextRandomState();
var rng = new Unity.Mathematics.Random(newRandomState);
return rng.NextFloat(range.minimum, range.maximum);
}
/// <summary>

12
com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs


}
/// <summary>
/// Generates a 32-bit non-zero hash using an unsigned integer seed
/// </summary>
/// <param name="seed">The unsigned integer to hash</param>
/// <returns>The calculated hash value</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Hash32NonZero(uint seed)
{
var hash = Hash32(seed);
return hash == 0u ? largePrime : hash;
}
/// <summary>
/// Based on splitmix64: http://xorshift.di.unimi.it/splitmix64.c
/// </summary>
/// <param name="x">64-bit value to hash</param>

2
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


/// <returns>The newly generated random state</returns>
public uint NextRandomState()
{
m_RandomState = SamplerUtility.Hash32(m_RandomState);
m_RandomState = SamplerUtility.Hash32NonZero(m_RandomState);
return m_RandomState;
}

正在加载...
取消
保存