Last active
June 17, 2022 15:26
-
-
Save Fast0n/1c34728a1dc7adce57ad0f6d8133d46d to your computer and use it in GitHub Desktop.
Generate Random Password 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(); | |
} | |
} | |
/* | |
ex. | |
GeneratePassword.randomString(30) | |
*/ |
What does this generate? I'm researching "generate random message" in Android Studio.
Strings like this:
I/System.out: MARCATEMP: HWdwTH04fZFuaPj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does this generate? I'm researching "generate random message" in Android Studio.