Thread safe version of the System.Random class.

The class inherits the System.Random and overrides its random numbers generation methods providing thread safety by guarding call to the base class with a lock. See documentation to System.Random for additional information about the base class.

Inheritance: System.Random
 /// <summary>
 /// Set seed of the random numbers generator.
 /// </summary>
 /// 
 /// <param name="seed">Seed value.</param>
 /// 
 /// <remarks>Resets random numbers generator initializing it with
 /// specified seed value.</remarks>
 /// 
 public void SetSeed( int seed )
 {
     rand = new ThreadSafeRandom( seed );
 }
        /// <summary>
		/// Initializes a new instance of the <see cref="UniformOneGenerator"/> class.
        /// </summary>
        /// 
        /// <remarks>Initializes random numbers generator with zero seed.</remarks>
        /// 
        public UniformOneGenerator( )
        {
            rand = new ThreadSafeRandom( 0 );
        }
        /// <summary>
		/// Initializes a new instance of the <see cref="UniformOneGenerator"/> class.
        /// </summary>
        /// 
        /// <param name="seed">Seed value to initialize random numbers generator.</param>
        /// 
        public UniformOneGenerator( int seed )
        {
            rand = new ThreadSafeRandom( seed );
        }
示例#4
0
 //Initialize the cards, players, and recording tool. Then start the game.
 public static void Start(List<Player> Players, int randomSeed)
 {
     Console.WriteLine("Initializing game with " + Players.String());
     decks = new Deck[3] { new Deck(), new Deck(), new Deck() };
     nobles = new Deck();
     players = new List<Player>(Players);
     random = new ThreadSafeRandom(randomSeed);
     gameOver = false;
     timer = Stopwatch.StartNew();
     switch (players.Count)
     {
         case 2:
             Gem.StartingGems = new Gem(4, 4, 4, 4, 4, 5);
             break;
         case 3:
             Gem.StartingGems = new Gem(5, 5, 5, 5, 5, 5);
             break;
         case 4:
             Gem.StartingGems = new Gem(7, 7, 7, 7, 7, 5);
             break;
         default:
             throw new Exception("Bad number of players: " + players.Count);
     }
 }