{
for (var i = 0; i < layerCount; i++)
var seed = scenario.NextRandomState();
var seed = SamplerState.NextRandomState();
var placementSamples = PoissonDiskSampling.GenerateSamples(
placementArea.x, placementArea.y, separationDistance, seed);
var offset = new Vector3(placementArea.x, placementArea.y, 0f) * -0.5f;
using System;
using System.Collections.Generic;
using UnityEngine.Experimental.Perception.Randomization.Samplers;
namespace UnityEngine.Experimental.Perception.Randomization.Randomizers.SampleRandomizers
/// </summary>
protected override void OnIterationStart()
public float Sample()
Initialize();
var rng = new Unity.Mathematics.Random(ScenarioBase.activeScenario.NextRandomState());
var rng = SamplerState.CreateGenerator();
return SamplerUtility.AnimationCurveSample(
m_IntegratedCurve, rng.NextFloat(), m_Interval, m_StartTime, m_EndTime);
}
/// <returns>The generated sample</returns>
return SamplerUtility.TruncatedNormalSample(
rng.NextFloat(), range.minimum, range.maximum, mean, standardDeviation);
return rng.NextFloat(range.minimum, range.maximum);
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine.Experimental.Perception.Randomization.Parameters;
static ScenarioBase s_ActiveScenario;
uint m_RandomState = SamplerUtility.largePrime;
bool m_SkipFrame = true;
bool m_FirstScenarioFrame = true;
bool m_WaitingForFinalUploads;
/// If true, this scenario will quit the Unity application when it's finished executing
[HideInInspector] public bool quitOnComplete = true;
/// <summary>
/// The random state of the scenario
public uint randomState => m_RandomState;
/// The name of the Json file this scenario's constants are serialized to/from.
if (currentIterationFrame == 0)
DatasetCapture.StartNewSequence();
m_RandomState = SamplerUtility.IterateSeed((uint)currentIteration, genericConstants.randomSeed);
SamplerState.randomState = SamplerUtility.IterateSeed((uint)currentIteration, genericConstants.randomSeed);
foreach (var randomizer in activeRandomizers)
randomizer.IterationStart();
var randomizer = m_Randomizers[currentIndex];
m_Randomizers.RemoveAt(currentIndex);
m_Randomizers.Insert(nextIndex, randomizer);
/// Generates a new random state and overwrites the old random state with the newly generated value
/// <returns>The newly generated random state</returns>
public uint NextRandomState()
m_RandomState = SamplerUtility.Hash32NonZero(m_RandomState);
return m_RandomState;
void ValidateParameters()
[Test]
public void ConsecutiveSamplesChangesState()
var state0 = activeScenario.randomState;
var state0 = SamplerState.randomState;
var state1 = activeScenario.randomState;
var state1 = SamplerState.randomState;
var state2 = activeScenario.randomState;;
var state2 = SamplerState.randomState;;
Assert.AreNotEqual(state0, state1);
Assert.AreNotEqual(state1, state2);
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Experimental.Perception.Randomization.Randomizers.SampleRandomizers;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
using UnityEngine.TestTools;
yield return CreateNewScenario(3, 1);
var seeds = new uint[3];
for (var i = 0; i < 3; i++)
seeds[i] = m_Scenario.NextRandomState();
seeds[i] = SamplerState.NextRandomState();
Assert.AreNotEqual(seeds[i], m_Scenario.NextRandomState());
Assert.AreNotEqual(seeds[i], SamplerState.NextRandomState());
PerceptionCamera SetupPerceptionCamera()
namespace UnityEngine.Experimental.Perception.Randomization.Samplers
public static class SamplerState
/// The central random state that all samplers mutate when generating random numbers
public static uint randomState = SamplerUtility.largePrime;
/// Creates a random number generator seeded with a unique random state
/// <returns>The seeded random number generator</returns>
public static Unity.Mathematics.Random CreateGenerator()
return new Unity.Mathematics.Random { state = NextRandomState() };
public static uint NextRandomState()
randomState = SamplerUtility.Hash32NonZero(randomState);
return randomState;
fileFormatVersion: 2
guid: dab4e2f4d003402193a82cfe926b91d0
timeCreated: 1611261496