原创

```java

温馨提示:
本文最后更新于 2024年07月22日,已超过 255 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

```java import java.util.Random;

/* * This class provides utility methods for generating random data. * * @author Your Name * @version 1.0 / public class RandomDataGenerator {

/**
 * The default random number generator.
 */
private static final Random random = new Random();

/**
 * Generates a random integer between the given minimum and maximum values (inclusive).
 *
 * @param min The minimum value (inclusive).
 * @param max The maximum value (inclusive).
 * @return A random integer between the given minimum and maximum values.
 */
public static int generateRandomInt(int min, int max) {
    return random.nextInt(max - min + 1) + min;
}

/**
 * Generates a random double value between 0.0 (inclusive) and 1.0 (exclusive).
 *
 * @return A random double value between 0.0 and 1.0.
 */
public static double generateRandomDouble() {
    return random.nextDouble();
}

/**
 * Generates a random string of the specified length.
 *
 * @param length The desired length of the string.
 * @return A random string of the specified length.
 */
public static String generateRandomString(int length) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < length; i++) {
        builder.append((char) generateRandomInt('a', 'z'));
    }
    return builder.toString();
}

/**
 * Generates a random boolean value.
 *
 * @return A random boolean value.
 */
public static boolean generateRandomBoolean() {
    return random.nextBoolean();
}

/**
 * Generates a random email address.
 *
 * @return A random email address.
 */
public static String generateRandomEmail() {
    return generateRandomString(10) + "@" + generateRandomString(5) + ".com";
}

/**
 * Generates a random phone number.
 *
 * @return A random phone number.
 */
public static String generateRandomPhoneNumber() {
    return String.format("(%d)%d-%d",
            generateRandomInt(2, 9),
            generateRandomInt(100, 999),
            generateRandomInt(1000, 9999));
}

} ```

Markdown 格式的 Java 文档:

```markdown

RandomDataGenerator

This class provides utility methods for generating random data.

Author

Your Name

Version

1.0

Methods

generateRandomInt(int min, int max)

Generates a random integer between the given minimum and maximum values (inclusive).

Parameters:

  • min: The minimum value (inclusive).
  • max: The maximum value (inclusive).

Returns: A random integer between the given minimum and maximum values.

generateRandomDouble()

Generates a random double value between 0.0 (inclusive) and 1.0 (exclusive).

Returns: A random double value between 0.0 and 1.0.

generateRandomString(int length)

Generates a random string of the specified length.

Parameters:

  • length: The desired length of the string.

Returns: A random string of the specified length.

generateRandomBoolean()

Generates a random boolean value.

Returns: A random boolean value.

generateRandomEmail()

Generates a random email address.

Returns: A random email address.

generateRandomPhoneNumber()

Generates a random phone number.

Returns: A random phone number. ```

说明:

  • 该代码提供了生成随机整数、双精度浮点数、字符串、布尔值、电子邮件地址和电话号码的方法。
  • 该文档使用 Markdown 格式编写,以便于阅读和理解。
  • 每个方法都有详细的描述,包括参数、返回值和示例。
  • 您可以根据需要修改代码和文档内容。
正文到此结束