namespace ACE { // important class, ensure unit tests pass for this public static class ThreadSafeRandom { private static readonly object randomMutex = new object(); private static readonly System.Random random = new System.Random(); /// /// Returns a random number between min and max /// public static float Next(float min, float max) { // todo: implement exactly the way AC handles it // inclusive/exclusive? lock (randomMutex) { return (float)(random.NextDouble() * (max - min) + min); } } /// /// Returns a random integer between min and max, inclusive /// /// The minimum possible value to return /// The maximum possible value to return public static int Next(int min, int max) { lock (randomMutex) { return random.Next(min, max + 1); } } public static uint Next(uint min, uint max) { lock (randomMutex) { return (uint)random.Next((int)min, (int)(max + 1)); } } } }