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

📄 jmrandom.java

📁 MSN客服自动化机器人
💻 JAVA
字号:
package jm.util;

import java.util.Random;
/**
 * 数据数
 */

public class JMRandom extends Random {

	/**
	 *
	 */
	private static final long serialVersionUID = -4819537676457525117L;
	int _start = 0;
	int _end = 0;

	/**
     * Creates a new random number generator. This constructor sets
     * the seed of the random number generator to a value very likely
     * to be distinct from any other invocation of this constructor.
     */
    public JMRandom() {
    	super();
    }

    /**
     * Creates a new random number generator using a single
     * <code>long</code> seed:
     * <blockquote><pre>
     * public Random(long seed) { setSeed(seed); }</pre></blockquote>
     * Used by method <tt>next</tt> to hold
     * the state of the pseudorandom number generator.
     *
     * @param   seed   the initial seed.
     * @see     java.util.Random#setSeed(long)
     */
    public JMRandom(long seed) {
        super(seed);
    }

    /**
     * Creates a new random number generator using a single
     */
    public JMRandom(int start,int end) {
    	super();
    	_start = start;
    	_end = end;
    }

    public void setMax (int end){
        _end = end;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JMRandom ra = new JMRandom();
		System.out.println(ra.nextRandomString(10,15));		
	}

	public int nextIntSnippet(){
		return (int)(_start+(_end-_start)*this.nextDouble());
	}

	String[] ELEMENT = {
			"0123456789", 							//1
			"qwertyuiopasdfghjklzxcvbnm",			//2
			"QWERTYUIOPASDFGHJKLZXCVBNM",			//4
			"~!@#$%^&*()_+|{}:\"<>?`-=\\[];',./'"	//8
			};
    String[] ELEMENT_TYPE = {
            "0", "1", "2", "12", "4", "14", "24", "124", "8", "18", "28", "128",
            "48", "148", "248", "1248"};

	/**
	 * 随机生成半角字符串序列
	 * @param length
	 * @param type	1~15
	 * @return
	 */
	public String nextRandomString(int length,int type){
		//获得基本数据类型
		String strType = "";
        for (int m = 0; m < ELEMENT_TYPE[type].length(); m++) {
            char c = ELEMENT_TYPE[type].charAt(m);
            //半角数值型字符串
            if (c == '1') {
            	strType = strType + ELEMENT[0];
            }
            //半角小写字符串
            else if (c == '2') {
            	strType = strType + ELEMENT[1];
            }
            //半角大写字符串
            else if (c == '4') {
            	strType = strType + ELEMENT[2];
            }
            //半角符号字符串
            else if (c == '8') {
            	strType = strType + ELEMENT[3];
            }
        }

        //生成数据
        String ret = "";
		int _startOld = _start;
		int _endOld = _end;
		_start = 0;
		_end = strType.length();
		for(int i = _start ; i <length ; i++){
			ret = ret +strType.charAt(this.nextIntSnippet());
		}
		_start = _startOld;
		_end = _endOld;

		return ret;
	}

}

⌨️ 快捷键说明

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