-
-
Save ynroot/51d54a8f662fff01f0087a474f430038 to your computer and use it in GitHub Desktop.
Generate Random String Android Studio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Random; | |
| public class GeneratePassword { | |
| /** | |
| * Genera una password RANDOM | |
| */ | |
| public static final String DATA = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz|!£$%&/=@#"; | |
| public static Random RANDOM = new Random(); | |
| public static String randomString(int len) { | |
| StringBuilder sb = new StringBuilder(len); | |
| for (int i = 0; i < len; i++) { | |
| sb.append(DATA.charAt(RANDOM.nextInt(DATA.length()))); | |
| } | |
| return sb.toString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment