Answers for "system.random reuses numbers"

C#
0

system.random reuses numbers

//Function to get a random number 
private static readonly Random random = new Random(); 
private static readonly object syncLock = new object(); 
public static int RandomNumber(int min, int max)
{
    lock(syncLock) { // synchronize
        return random.Next(min, max);
    }
}
Posted by: Guest on March-16-2020

C# Answers by Framework

Browse Popular Code Answers by Language