```java

nisan發表於2024-07-26
import java.util.Random;

/**
 * This class provides methods for generating random numbers.
 *
 * @author Bard
 * @version 1.0
 * @since 2023-10-27
 */
public class RandomNumberGenerator {

    /**
     * A private instance of the Random class.
     */
    private static final Random RANDOM = new Random();

    /**
     * Generates a random integer between 0 (inclusive) and the specified upper bound (exclusive).
     *
     * @param upperBound The upper bound (exclusive).
     * @return A random integer between 0 and the upper bound (exclusive).
     */
    public static int getRandomInteger(int upperBound) {
        return RANDOM.nextInt(upperBound);
    }

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

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

Markdown 檔案

# RandomNumberGenerator

This class provides methods for generating random numbers.

## Author

Bard

## Version

1.0

## Since

2023-10-27

## Methods

### getRandomInteger(int upperBound)

Generates a random integer between 0 (inclusive) and the specified upper bound (exclusive).

**Parameters:**

* `upperBound`: The upper bound (exclusive).

**Returns:**

A random integer between 0 and the upper bound (exclusive).

### getRandomDouble()

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

**Returns:**

A random double between 0.0 and 1.0 (exclusive).

### getRandomBoolean()

Generates a random boolean value.

**Returns:**

A random boolean value.

This Markdown file provides a comprehensive documentation for the RandomNumberGenerator class, including its purpose, author, version, methods, and their descriptions.

相關文章