⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 randomizer.java

📁 java 的源代码
💻 JAVA
字号:
package com.reddragon2046.base.utilities.data.util;

import java.util.Random;

public class Randomizer extends Random
{

    public Randomizer()
    {
    }

    public Randomizer(long seed)
    {
        super(seed);
    }

    public int nextInt(int hi)
    {
        return nextInt(1, hi);
    }

    public int nextInt(int lo, int hi)
    {
        if(lo > hi)
            throw new IllegalArgumentException("invalid range: " + lo + " > " + hi);
        else
            return Math.abs(super.nextInt()) % ((hi - lo) + 1) + lo;
    }

    public long nextLong(long hi)
    {
        return nextLong(1L, hi);
    }

    public long nextLong(long lo, long hi)
    {
        if(lo > hi)
            throw new IllegalArgumentException("invalid range: " + lo + " > " + hi);
        else
            return Math.abs(super.nextLong()) % ((hi - lo) + 1L) + lo;
    }

    public float nextFloat(float hi)
    {
        return nextFloat(1.0F, hi);
    }

    public float nextFloat(float lo, float hi)
    {
        if(lo > hi)
            throw new IllegalArgumentException("invalid range: " + lo + " > " + hi);
        else
            return Math.abs(super.nextFloat()) % ((hi - lo) + 1.0F) + lo;
    }

    public double nextDouble(double hi)
    {
        return nextDouble(1.0D, hi);
    }

    public double nextDouble(double lo, double hi)
    {
        if(lo > hi)
            throw new IllegalArgumentException("invalid range: " + lo + " > " + hi);
        else
            return Math.abs(super.nextDouble()) % ((hi - lo) + 1.0D) + lo;
    }

    public static int getInt(int hi)
    {
        return getInt(1, hi);
    }

    public static int getInt(int lo, int hi)
    {
        return random.nextInt(lo, hi);
    }

    public static long getLong(long hi)
    {
        return getLong(1L, hi);
    }

    public static long getLong(long lo, long hi)
    {
        return random.nextLong(lo, hi);
    }

    public static float getFloat(float hi)
    {
        return getFloat(1.0F, hi);
    }

    public static float getFloat(float lo, float hi)
    {
        return random.nextFloat(lo, hi);
    }

    public static double getDouble(double hi)
    {
        return getDouble(1.0D, hi);
    }

    public static double getDouble(double lo, double hi)
    {
        return random.nextDouble(lo, hi);
    }

    static Randomizer random = new Randomizer();
    static final long serialVersionUID = 0x7f582062a4ec4a94L;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -