using System; using System.Collections.Generic; using System.Text; namespace RandomOut ...{ publicinterface IRandom ...{ void BringToWorld(); void MixedRandomized(); } publicabstractclass TPoker : IRandom ...{ publicvirtualvoid BringToWorld() ...{ } publicabstractvoid MixedRandomized(); } publicclass Pokers : TPoker ...{ private List<int> _poker; private Random random; privateint baseNum; privateint extra; /**////<summary> /// Summary description for Pokers ///</summary> public Pokers() ...{ random =new Random(DateTime.Now.Millisecond); Random rdm =new Random(); baseNum = rdm.Next(1, 1000); extra = rdm.Next(1, 1000); } /**////<summary> /// Complete System of Residues Expression Generator ///</summary> ///<param name="index">An index to generate an index using Linear Congruence Generator</param> ///<returns></returns> privateint EquationVendor(int index) ...{ return (baseNum * index + extra); } /**////<summary> /// Randomized the Order of the Poker ///</summary> ///<param name="count">The total pieces of Poker</param> ///<returns></returns> privateint[] Randomized(int count) ...{ int[] indexes =newint[count]; for (int i =0; i < count; i++) ...{ indexes[i] = EquationVendor(i) % count; } return indexes; } /**////<summary> /// Generate a set of Poker ///</summary> publicoverridevoid BringToWorld() ...{ _poker =new List<int>(); _poker.Add(0); _poker.Add(0); for (int i =1; i <14; i++) ...{ for (int j =0; j <4; j++) ...{ _poker.Add(i); } } } /**////<summary> /// Randomized the Order of the Poker, using Complete System of Residues ///</summary> publicoverridevoid MixedRandomized() ...{ int[] indexes = Randomized(_poker.Count); List<int> tmp =new List<int>(); foreach (int index in indexes) ...{ tmp.Add(_poker[index]); } _poker = tmp; } /**////<summary> /// Shuffle the Poker, just another method different from MixedRandomized ///</summary> publicvoid Shuffle() ...{ int tmp =0; int card =0; for (int i =0; i < _poker.Count; i++) ...{ tmp = random.Next(0, _poker.Count); card = _poker[tmp]; _poker[tmp] = _poker[i]; _poker[i] = card; } } /**////<summary> /// A hand to generate the parameters for the Complete System of Residues Expression Generator ///</summary> publicvoid Hand() ...{ Random rdm =new Random(); baseNum = rdm.Next(1, 1000); extra = rdm.Next(1, 1000); while (!IsCorrectBaseNum(baseNum -1)) ...{ baseNum = rdm.Next(1, 1000); } while (!IsCorrectExtra(extra)) ...{ extra = rdm.Next(1, 1000); } } /**////<summary> /// Check if the BaseNum for Complete System of Residues Expression Generator is Correct ///</summary> ///<param name="num">BaseNum for Complete System of Residues</param> ///<returns></returns> privatebool IsCorrectBaseNum(int num) ...{ if ((num %3==0) && (num %2) ==0) returntrue; returnfalse; } /**////<summary> /// Check if the Extra for Complete System of Residues Expression Generator is Correct ///</summary> ///<param name="ex">Extra for Complete System of Residues</param> ///<returns></returns> privatebool IsCorrectExtra(int ex) ...{ if (GreatCommonDivisor(ex, _poker.Count) ==1) returntrue; returnfalse; } /**////<summary> /// Gets the Great Common Divisor ///</summary> ///<param name="a">First parameter</param> ///<param name="b">Second parameter</param> ///<returns>Great Common Divisor</returns> privateint GreatCommonDivisor(int a, int b) ...{ int dividend, divisor, tmp; dividend = a > b ? a : b; divisor = a < b ? a : b; while (dividend % divisor !=0) ...{ tmp = divisor; divisor = dividend % divisor; dividend = tmp; } return divisor; } /**////<summary> /// Gets the Least Common Multiple ///</summary> ///<param name="a">First parameter</param> ///<param name="b">Second parameter</param> ///<returns>Least Common Multiple</returns> privateint LeastCommonMultiple(int a, int b) ...{ int gcd, lcm; gcd = GreatCommonDivisor(a, b); lcm = (a / gcd) * (b / gcd) * gcd; return lcm; } /**////<summary> /// Override ToString to a specified Format Style only for Pokers ///</summary> ///<returns></returns> publicoverridestring ToString() ...{ string ret =string.Empty; for (int i =0; i < _poker.Count; i++) ...{ if (i == _poker.Count -1) ret += _poker[i].ToString(); else ret += _poker[i].ToString() +"->"; } return ret; } /**////<summary> /// Gets a Poker ///</summary> public List<int> Poker ...{ get...{ return _poker; } } } }