| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ServiceStackBenchmark
- {
- internal sealed class SafeRandom
- {
- private static volatile SafeRandom instance;
- private static object syncRoot = new object();
- private static Random random;
- private SafeRandom()
- {
- random = new Random();
- }
- public int Next()
- {
- int result;
- lock (random)
- {
- result = random.Next();
- }
- return result;
- }
- public int Next(int maxValue)
- {
- int result;
- lock (random)
- {
- result = random.Next(maxValue);
- }
- return result;
- }
- public int Next(int minValue, int maxValue)
- {
- int result;
- lock (random)
- {
- result = random.Next(minValue, maxValue);
- }
- return result;
- }
- public static SafeRandom Instance
- {
- get
- {
- if (instance == null)
- {
- lock (syncRoot)
- {
- if (instance == null)
- {
- instance = new SafeRandom();
- }
- }
- }
- return instance;
- }
- }
- }
- }
|