/// <summary>
        /// Test the validity of the DenseTernaryPolynomial implementation
        /// </summary>
        /// 
        /// <returns>State</returns>
        public string Test()
        {
            try
            {
                CheckTernarity(PolynomialGeneratorForTesting.generateRandom(1499));

                CSPRng rng = new CSPRng();
                for (int i = 0; i < 10; i++)
                {
                    int N = rng.Next(2000) + 10;
                    int numOnes = rng.Next(N);
                    int numNegOnes = rng.Next(N - numOnes);
                    CheckTernarity(DenseTernaryPolynomial.GenerateRandom(N, numOnes, numNegOnes, rng));
                }
                OnProgress(new TestEventArgs("Passed DenseTernaryPolynomial Ternarity"));

                return SUCCESS;
            }
            catch (Exception Ex)
            {
                string message = Ex.Message == null ? "" : Ex.Message;
                throw new Exception(FAILURE + message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get an open and randomly selected port number within a range
        /// </summary>
        /// 
        /// <param name="From">The minimum port number (default is 49152)</param>
        /// <param name="To">The maximum port number (default is 65535)</param>
        /// <returns>An open port number</returns>
        /// 
        /// <exception cref="CryptoSocketException">Thrown if the operation is in an error state</exception>
        public int NextOpenPort(int From = 49152, int To = 65535)
        {
            CSPRng rnd = new CSPRng();

            int port = -1;

            do
            {
                if (IsPortOpen((port = rnd.Next(From, To))))
                    break;

            } while (true);

            return port;
        }
        private void GenerateRandom()
        {
            CSPRng rng = new CSPRng();
            Verify(SparseTernaryPolynomial.GenerateRandom(743, 248, 248, rng));

            for (int i = 0; i < 10; i++)
            {
                int N = rng.Next(2000) + 10;
                int numOnes = rng.Next(N);
                int numNegOnes = rng.Next(N - numOnes);
                Verify(SparseTernaryPolynomial.GenerateRandom(N, numOnes, numNegOnes, rng));
            }
        }