![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 阿宗 ![]()
![]() |
如何隨機產生如下的字串(長度介於15個字元及5個字元之間): dsf60fe324g90h8 或 fj2g6kj9v |
別忘捐VP感謝幫助你的人 | 新手會員瞧一瞧 |
1樓
最有價值解答
Bryan(不來ㄣ) ![]() ![]() |
我英文只寫a~g(我懶),h~z你在往後加上即可
class RandomString
{
public static void main(String[] args)
{
for (int i=0;i<20;i++)
{
System.out.println(getRandomString());
}
}
public static String getRandomString()
{
char seeds[] = {'a','b','c','d','e','f','g','0','1','2','3','4','5','6','7','8','9','0'};
int strLen = (int)Math.round(Math.random() * 10) + 5;
char randStr[] = new char[strLen];
for (int i=0;i<randStr.length;i++)
{
randStr[i] = seeds[(int)Math.round(Math.random() * (seeds.length - 1))];
}
String returnStr = new String(randStr);
return returnStr;
}
}
|
2樓
作者回應
阿宗 ![]() |
感謝!超級感謝!
本篇文章回覆於2005-03-03 17:45
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔-- |
回覆 |
如要回應,請先登入. |