public static String RandomTextString(RandomGenerator rand) { int length = rand.UniformInt(0x2000); StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; ++i) { int x = rand.UniformInt(100); if (x < 95) { // ASCII sb.append((char) (0x20 + rand.UniformInt(0x60))); } else if (x < 98) { // Supplementary character x = rand.UniformInt(0x400) + 0xd800; sb.append((char) x); x = rand.UniformInt(0x400) + 0xdc00; sb.append((char) x); } else { // BMP character x = 0x20 + rand.UniformInt(0xffe0); if (x >= 0xd800 && x < 0xe000) { // surrogate code unit, generate ASCII instead x = 0x20 + rand.UniformInt(0x60); } sb.append((char) x); } } return sb.toString(); }
public static String RandomDecimalString(RandomGenerator r) { int count = r.UniformInt(40) + 1; StringBuilder sb = new StringBuilder(); if (r.UniformInt(2) == 0) { sb.append('-'); } for (int i = 0; i < count; ++i) { if (i == 0 && count > 1) { sb.append((char) ('1' + r.UniformInt(9))); } else { sb.append((char) ('0' + r.UniformInt(10))); } } if (r.UniformInt(2) == 0) { sb.append('.'); count = r.UniformInt(30) + 1; for (int i = 0; i < count; ++i) { sb.append((char) ('0' + r.UniformInt(10))); } } if (r.UniformInt(2) == 0) { sb.append('E'); count = (r.UniformInt(100) < 10) ? r.UniformInt(5000) : r.UniformInt(20); if (count != 0) { sb.append(r.UniformInt(2) == 0 ? '+' : '-'); } sb.append(TestCommon.IntToString(count)); } return sb.toString(); }
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()); }
public static String RandomBigIntString(RandomGenerator r) { int count = r.UniformInt(400) + 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 sb.toString(); }