廉頗老矣,尚能飯否

          java:從技術(shù)到管理

          常用鏈接

          統(tǒng)計(jì)

          最新評(píng)論

          Java產(chǎn)生隨機(jī)數(shù)代碼【轉(zhuǎn)載】

          //根據(jù)不同的難度產(chǎn)生隨機(jī)字母和數(shù)字
          for(int i=0; readomNumStart.length()<4; i++) {
          if(difficult == 1) {

          //產(chǎn)生隨機(jī)的0-9的數(shù)字
          a = String.valueOf((int)(Math.random() * 10)) ;
          }
          if(difficult == 2) {

          //在0-9和a,b,c,d中隨機(jī)產(chǎn)生。
          String[] readomWord = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d"};
          int readomWordIndex = (int)(Math.random() * 13);
          a = readomWord[readomWordIndex];
          }
          if(difficult == 3) {

          //產(chǎn)生隨機(jī)的字母
          char readomLetter = (char)(Math.random ()*26+'a');
          a = String.valueOf(readomLetter) ;
          }
          if(difficult == 4) {

          //產(chǎn)生隨機(jī)的數(shù)字和字母的組合
          String[] readomHard = new String[20];
          int readomWordIndex = (int)(Math.random() * 19);
          for(int j=0; j<20; j++) {
          int readomWordNum = (int)(Math.random() * 10);
          char readomLetter = (char)(Math.random ()*26+'a');
          if(readomWordNum % 2 == 0) {
          readomHard[j] = readomWordNum + "";
          }else{
          readomHard[j] = String.valueOf(readomLetter);
          }
          }
          a = readomHard[readomWordIndex];
          }

          //
          char[] numbersAndLetters = ("0123456789" + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
          char[] randBuffer = new char[length];
          for (int i = 0; i < randBuffer.length; i++) {
          randBuffer[i] = numbersAndLetters[randGen.nextInt(numbersAndLetters.length)];
          }
          return new String(randBuffer);


          柳德才
          13691193654
          18942949207
          QQ:422157370
          liudecai_zan@126.com
          湖北-武漢-江夏-廟山

          posted on 2009-04-08 16:10 liudecai_zan@126.com 閱讀(155) 評(píng)論(0)  編輯  收藏 所屬分類: 程序人生

          主站蜘蛛池模板: 定结县| 莫力| 井冈山市| 徐水县| 巴东县| 常山县| 河池市| 永定县| 内江市| 北碚区| 布尔津县| 安平县| 河津市| 海宁市| 绥滨县| 沂水县| 玉林市| 平阴县| 翁牛特旗| 涿州市| 汉源县| 仁怀市| 宣城市| 星子县| 金秀| 申扎县| 阿拉善盟| 神木县| 赤峰市| 云安县| 昌黎县| 桑日县| 平遥县| 松阳县| 阆中市| 赫章县| 麦盖提县| 河津市| 交城县| 泰顺县| 安吉县|