Bei Verwendung von Unity 2017.2.0f3 scheint UnityEngine.Random auf mehreren Plattformen die gleichen Ergebnisse zu liefern. Getestet unter Windows 10, macOS 10.12 Sierra und Android 7.
Zum Testen habe ich eine von mir erstellte SeedFactory-Klasse verkleinert:
using UnityEngine;
public class SeedFactory {
private Random.State state;
public SeedFactory (int seed) {
Random.InitState(seed);
state = Random.state;
}
// Set Unity's global Random state with this SeedFactory's state, get a random int,
// then set our SeedFactory's state with the new state.
// (this allows us to use multiple SeedFactories for multiple paths of determinism
// if desired)
public int GetRandomInt (int minInclusive, int maxExclusive) {
Random.state = state;
int randomInt = Random.Range(minInclusive, maxExclusive);
state = Random.state;
return randomInt;
}
}
Und ein MonoBehaviour, um den Test durchzuführen:
public class SeedTest : MonoBehaviour {
void Start () {
SeedFactory seedFactory = new SeedFactory(123456789);
string result = "";
for (int i = 0; i < 20; i++) {
result += seedFactory.GetRandomInt(int.MinValue, int.MaxValue) + ", ";
}
Debug.Log(result);
}
}
Und die Ergebnisse waren alle gleich:
Windows Editor:
217814258, 711215697, 1793372675, -1318111305, -513578644, 1776128467, -1503243711, -285471819, -1800526065, -1845985472, -2061970588, 188207569, 1858341351, -1139513088, 2136219157, 1255727479, -2070068486, 459175680, 1151694536, 1232856178,
Windows Standalone:
217814258, 711215697, 1793372675, -1318111305, -513578644, 1776128467, -1503243711, -285471819, -1800526065, -1845985472, -2061970588, 188207569, 1858341351, -1139513088, 2136219157, 1255727479, -2070068486, 459175680, 1151694536, 1232856178,
macOS Standalone:
217814258, 711215697, 1793372675, -1318111305, -513578644, 1776128467, -1503243711, -285471819, -1800526065, -1845985472, -2061970588, 188207569, 1858341351, -1139513088, 2136219157, 1255727479, -2070068486, 459175680, 1151694536, 1232856178,
Android:
217814258, 711215697, 1793372675, -1318111305, -513578644, 1776128467, -1503243711, -285471819, -1800526065, -1845985472, -2061970588, 188207569, 1858341351, -1139513088, 2136219157, 1255727479, -2070068486, 459175680, 1151694536, 1232856178,