diff --git a/RandomString.java b/RandomString.java new file mode 100644 index 0000000..a283f0c --- /dev/null +++ b/RandomString.java @@ -0,0 +1,45 @@ +import java.util.Scanner; +import java.util.Random; +/** + * GarbledCodeGenerator - 一个可控制长度的乱码生成器 + * + * Copyright (C) 2026 edwardp20 + * + * 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 . + */ +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; + } +} \ No newline at end of file