Monday, 2 November 2015

Random Number Generator to Generate Different Numbers

C# Random method is initialized using the clock. That's why it generates same value every time it calls. Here is the solution to generates different numbers:


private static readonly Random random = new Random();
private static readonly object syncLock = new object();

public static int RandomNumber(int min, int max)
{
    // synchronize
    lock (syncLock)
    {
        return random.Next(min, max);
    }
}


No comments:

Analysis Service in Power BI Report Server

 We couldn’t connect to the Analysis Services server. Make sure you’ve entered the connection string correctly... link