Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions RandomString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.util.Scanner;
import java.util.Random;
/**
* GarbledCodeGenerator - 一个可控制长度的乱码生成器
*
* Copyright (C) 2026 edwardp20 <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
public class RandomString {
public static void main(String[] args) {
String[] arr = {
"1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z"
};
Scanner s = new Scanner(System.in);
String result = "";
IO.println("请输入你要的长度");
int longer = s.nextInt();
for(int i = 1;i <= longer;i++){
int randomIndex = getRandomNumber(arr.length);
result = result + arr[randomIndex];
}
IO.println(result);
}

public static int getRandomNumber(int random) {
Random r = new Random();
int randomNumber = r.nextInt(random);
return randomNumber;
}
}