public void seed(object s) { if (s == null) { seed(); return; } int newSeed; if (s is int) { newSeed = (int)s; } else { if (!PythonContext.IsHashable(s)) { throw PythonOps.TypeError("unhashable type: '{0}'", PythonOps.GetPythonTypeName(s)); } newSeed = s.GetHashCode(); } lock (this) { _rnd = new System.Random(newSeed); } }
public void seed(object s = null) { int newSeed; switch (s) { case null: newSeed = DateTime.Now.GetHashCode(); break; case int i: newSeed = i; break; default: if (!PythonContext.IsHashable(s)) { throw PythonOps.TypeError("unhashable type: '{0}'", PythonOps.GetPythonTypeName(s)); } newSeed = s.GetHashCode(); break; } lock (this) { _rnd = new RandomGen(newSeed); } }