Sylloge
A C# helper library
code/Data/RNG.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 
00006 namespace Sylloge
00007 {
00008     public static class RNG
00009     {
00010         private static object m_rlock = new object();
00011         private static Random m_rand = new Random();
00012 
00013         public static int Next()
00014         {
00015             lock (RNG.m_rlock) {
00016                 return m_rand.Next();
00017             }
00018         }
00019 
00020         public static int Next(int maxVal)
00021         {
00022             lock (RNG.m_rlock) {
00023                 return m_rand.Next(maxVal);
00024             }
00025         }
00026 
00027         public static int Next(int minVal, int maxVal)
00028         {
00029             lock (RNG.m_rlock) {
00030                 return m_rand.Next(minVal, maxVal);
00031             }
00032         }
00033 
00034         public static bool Percent(int pct)
00035         {
00036             return RNG.Next(1, 101) <= pct;
00037         }
00038     }
00039 }
 All Classes Namespaces Files Functions Variables Enumerations Properties Events