当前位置:编程学习 > JSP >>

java随机生成6位数字字符数组

 代码如下 复制代码

package com.system.oss.common.util;
/**
 * 动态生成随机字符数组
 * 
 * @author 苏持恒
 */
public class ShortMessageCodeUntil
{


    /**
     * 随机生成4位数字字符数组
     * 
     * @return rands
     */
    public static char[] generateCheckCode()
    {
        String chars = "0123456789";
        char[] rands = new char[4];
        for (int i = 0; i < 4; i++)
        {
            int rand = (int) (Math.random() * 10);
            rands[i] = chars.charAt(rand);
        }
        return rands;
    }


    /**
     * 随机生成6位数字字符数组
     * 
     * @return rands
     */
    public static char[] generateCheckPass()
    {
        String chars = "0123456789";
        char[] rands = new char[6];
        for (int i = 0; i < 6; i++)
        {
            int rand = (int) (Math.random() * 10);
            rands[i] = chars.charAt(rand);
        }
        return rands;
    }


}

补充:Jsp教程,Java基础 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,