示例#1
0
 public static ERational RandomERational(RandomGenerator rand) {
   EInteger bigintA = RandomEInteger(rand);
   EInteger bigintB = RandomEInteger(rand);
   if (bigintB.isZero()) {
     bigintB = EInteger.FromInt32(1);
   }
   return ERational.Create(bigintA, bigintB);
 }
示例#2
0
 public static EFloat RandomEFloat(RandomGenerator r) {
   if (r.UniformInt(100) == 0) {
     int x = r.UniformInt(3);
     if (x == 0) {
       return EFloat.PositiveInfinity;
     }
     if (x == 1) {
       return EFloat.NegativeInfinity;
     }
     if (x == 2) {
       return EFloat.NaN;
     }
   }
   return EFloat.Create(RandomEInteger(r), EInteger.FromInt64(r.UniformInt(400) - 200));
 }
示例#3
0
 public static EInteger RandomSmallIntegral(RandomGenerator r) {
   int count = r.UniformInt(20) + 1;
   StringBuilder sb = new StringBuilder();
   if (r.UniformInt(2) == 0) {
     sb.append('-');
   }
   for (int i = 0; i < count; ++i) {
     if (i == 0) {
       sb.append((char) ('1' + r.UniformInt(9)));
     } else {
       sb.append((char) ('0' + r.UniformInt(10)));
     }
   }
   return EInteger.FromString(sb.toString());
 }
示例#4
0
 public static EInteger RandomEInteger(RandomGenerator r) {
   int selection = r.UniformInt(100);
   if (selection < 40) {
     StringAndBigInt sabi = StringAndBigInt.Generate(r, 16);
     return sabi.getBigIntValue();
   }
   if (selection < 50) {
     StringAndBigInt sabi = StringAndBigInt.Generate(r, 2 + r.UniformInt(35));
     return sabi.getBigIntValue();
   } else {
     int count = r.UniformInt(400) + 1;
     byte[] bytes = new byte[count];
     for (int i = 0; i < count; ++i) {
       bytes[i] = (byte) ((int) r.UniformInt(256));
     }
     return EInteger.FromBytes(bytes, true);
   }
 }