public static String RandomDecimalString( IRandomGenExtended r, bool extended, bool limitedExponent) { if (r == null) { throw new ArgumentNullException(nameof(r)); } if (r.GetInt32(100) < 95) { return(RandomDecimalStringShort(r, extended)); } long count = ((long)r.GetInt32(MaxNumberLength) * r.GetInt32(MaxNumberLength)) / MaxNumberLength; count = ((long)count * r.GetInt32(MaxNumberLength)) / MaxNumberLength; count = Math.Max(1, count); long afterPointCount = 0; long exponentCount = 0; var smallExponent = false; if (r.GetInt32(2) == 0) { afterPointCount = ((long)r.GetInt32(MaxNumberLength) * r.GetInt32(MaxNumberLength)) / MaxNumberLength; afterPointCount = ((long)afterPointCount * r.GetInt32(MaxNumberLength)) / MaxNumberLength; afterPointCount = Math.Max(1, afterPointCount); } if (r.GetInt32(2) == 0) { if (limitedExponent || r.GetInt32(10) > 0) { exponentCount = 5; } else { exponentCount = ((long)r.GetInt32(MaxNumberLength) * r.GetInt32(MaxNumberLength)) / MaxNumberLength; exponentCount = ((long)exponentCount * r.GetInt32(MaxNumberLength)) / MaxNumberLength; exponentCount = ((long)exponentCount * r.GetInt32(MaxNumberLength)) / MaxNumberLength; exponentCount = Math.Max(1, exponentCount); } } var bufferSize = (int)Math.Min( Int32.MaxValue, 8 + count + afterPointCount + exponentCount); var sb = new StringBuilder(bufferSize); if (r.GetInt32(2) == 0) { sb.Append('-'); } if (!extended) { sb.Append((char)('1' + r.GetInt32(9))); --count; } AppendRandomDecimalsLong(r, sb, count); if (afterPointCount > 0) { sb.Append('.'); AppendRandomDecimalsLong(r, sb, afterPointCount); } if (exponentCount > 0) { int rr = r.GetInt32(3); if (rr == 0) { sb.Append('E'); } else if (rr == 1) { sb.Append("E+"); } else if (rr == 2) { sb.Append("E-"); } if (smallExponent) { sb.Append(TestCommon.IntToString(r.GetInt32(10000))); } else { AppendRandomDecimalsLong(r, sb, exponentCount); } } return(sb.ToString()); }