Exemple #1
0
        static void Random(Digits mod, Digits arr, int n, Random generator)
        {
            Debug.Assert(!arr._Overlaps(mod), "overlapping arguments");
            int sigDigitN = n;

            while (sigDigitN > 0 && mod[sigDigitN - 1] == 0)
            {
                Debug.Assert(false, "untested code");
                arr[sigDigitN - 1] = 0;
                sigDigitN--;
            }
            if (sigDigitN == 0)
            {
                throw new ArgumentException();
            }
            Digit nlead = mod[sigDigitN - 1];
            int   ntry  = 0;

            do
            {
                ntry++;
                Debug.Assert(ntry <= 100, "too many iterations");
                Digits.Random(arr, sigDigitN - 1, generator);
                arr[sigDigitN - 1] = Digit.Random(0, nlead, generator);
            } while (Digits.Compare(arr, mod, sigDigitN) >= 0);
        }
Exemple #2
0
 Random(Digits digits, int digitN, Random generator)
 {
     for (int i = 0; i < digitN; i++)
     {
         digits[i] = Digit.Random(generator);
     }
 }