java 随机加强
package
com.upengs.util;
/** */ /**
* <ul>
* <li>Title:[RandomGenerator]</li>
* <li>Description: [随机生成器]</li>
* <li>Copyright 2009 Upengs Co., Ltd.</li>
* <li>All right reserved.</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @version 1.0
*/
public class RandomGenerator
{
/** *//**
* <ul>
* <li>Description:[得到一个小写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getLower()
{
return String.valueOf((char) getIntRange(97, 122));
}
/** *//**
* <ul>
* <li>Description:[随机得到多个小写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getLowers(int length)
{
StringBuffer lowers = new StringBuffer();
for (int i = 0; i < length; i++)
{
lowers.append(getLower());
}
return lowers.toString();
}
/** *//**
* <ul>
* <li>Description:[得到一个大写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getUpper()
{
return String.valueOf((char) getIntRange(65, 90));
}
/** *//**
* <ul>
* <li>Description:[随机得到多个大写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getUppers(int length)
{
StringBuffer upper = new StringBuffer();
for (int i = 0; i < length; i++)
{
upper.append(getUpper());
}
return upper.toString();
}
/** *//**
* <ul>
* <li>Description:[随机得到大写字母或小写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getAlpha()
{
if (getIntRange(0, 1) == 0)
{
return getUpper();
}
return getLower();
}
/** *//**
* <ul>
* <li>Description:[随机得到一个由大小字母或小写字母的字符串]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getAlphas(int length)
{
StringBuffer alphas = new StringBuffer();
for (int i = 0; i < length; i++)
{
alphas.append(getUpper());
}
return alphas.toString();
}
/** *//**
* <ul>
* <li>Description:[得到一个字母或数字]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getBeta()
{
if (getIntRange(0, 1) == 0)
{
return getAlpha();
}
return String.valueOf(getIntRange(0, 9));
}
/** *//**
* <ul>
* <li>Description:[随机得到一个字母或数字的字符串]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getBetas(int length)
{
StringBuffer betas = new StringBuffer();
for (int i = 0; i < length; i++)
{
betas.append(getBeta());
}
return betas.toString();
}
/** *//**
* <ul>
* <li>Description:[随机生成某个范围内的随机数,包含两端的数]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param start
* @param end
* @return
*/
public static int getIntRange(int start, int end)
{
return (int) (Math.random() * (end - start + 1) + start);
}
/** *//**
* <ul>
* <li>Description:[得到一个随机整数]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param end
* @return
*/
public static int getInt(int end)
{
return getIntRange(0, end);
}
}
/** */ /**
* <ul>
* <li>Title:[RandomGenerator]</li>
* <li>Description: [随机生成器]</li>
* <li>Copyright 2009 Upengs Co., Ltd.</li>
* <li>All right reserved.</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @version 1.0
*/
public class RandomGenerator
{
/** *//**
* <ul>
* <li>Description:[得到一个小写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getLower()
{
return String.valueOf((char) getIntRange(97, 122));
}
/** *//**
* <ul>
* <li>Description:[随机得到多个小写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getLowers(int length)
{
StringBuffer lowers = new StringBuffer();
for (int i = 0; i < length; i++)
{
lowers.append(getLower());
}
return lowers.toString();
}
/** *//**
* <ul>
* <li>Description:[得到一个大写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getUpper()
{
return String.valueOf((char) getIntRange(65, 90));
}
/** *//**
* <ul>
* <li>Description:[随机得到多个大写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getUppers(int length)
{
StringBuffer upper = new StringBuffer();
for (int i = 0; i < length; i++)
{
upper.append(getUpper());
}
return upper.toString();
}
/** *//**
* <ul>
* <li>Description:[随机得到大写字母或小写字母]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getAlpha()
{
if (getIntRange(0, 1) == 0)
{
return getUpper();
}
return getLower();
}
/** *//**
* <ul>
* <li>Description:[随机得到一个由大小字母或小写字母的字符串]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getAlphas(int length)
{
StringBuffer alphas = new StringBuffer();
for (int i = 0; i < length; i++)
{
alphas.append(getUpper());
}
return alphas.toString();
}
/** *//**
* <ul>
* <li>Description:[得到一个字母或数字]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @return
*/
public static String getBeta()
{
if (getIntRange(0, 1) == 0)
{
return getAlpha();
}
return String.valueOf(getIntRange(0, 9));
}
/** *//**
* <ul>
* <li>Description:[随机得到一个字母或数字的字符串]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param length
* @return
*/
public static String getBetas(int length)
{
StringBuffer betas = new StringBuffer();
for (int i = 0; i < length; i++)
{
betas.append(getBeta());
}
return betas.toString();
}
/** *//**
* <ul>
* <li>Description:[随机生成某个范围内的随机数,包含两端的数]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param start
* @param end
* @return
*/
public static int getIntRange(int start, int end)
{
return (int) (Math.random() * (end - start + 1) + start);
}
/** *//**
* <ul>
* <li>Description:[得到一个随机整数]</li>
* <li>Created by [Huyvanpull] [2011-2-25]</li>
* <li>Midified by [modifier] [modified time]</li>
* </ul>
*
* @param end
* @return
*/
public static int getInt(int end)
{
return getIntRange(0, end);
}
}