Generate Custom Session ID using Java
In this example, We will show you about, How to Generate Custom Session ID using Java. The example were tested with environment and shared in the post.
SessionIdGenerator.java
package com.dineshkrish.string; import java.security.SecureRandom; import java.math.BigInteger; /** * * @author Dinesh Krishnan * */ public final class SessionIdGenerator { private static final int LENGTH = 32; private static SecureRandom random = new SecureRandom(); public static String getSessionId() { BigInteger bigInteger = new BigInteger(130, random); String sessionId = String.valueOf(bigInteger.toString(LENGTH)); return sessionId.toUpperCase(); } public static void main(String[] args) { for (int i = 1; i <= 10; i++) { System.out.println("Session ID "+i+": "+SessionIdGenerator.getSessionId()); } } }
Output
Session ID 1: QH2QMK7VC6S3C9AAUEQQHSOA5I
Session ID 2: SSO0T30AE608AJA4E4QCRHMMRA
Session ID 3: F79RV24T8OKAL0H23UO5Q6H6NJ
Session ID 4: V775PA7KL78EF8JUTR3OINPM86
Session ID 5: J5SHDPBG7VU1ARGF1M88856384
Session ID 6: Q51RMLUUKC4IIO6FKLF7EI8M04
Session ID 7: MLC993VESVUP8G7MMSUM697V2C
Session ID 8: AVN8BDB0ITPH1DHFDM7K43JIO5
Session ID 9: BEKEJK56BJHEGE4C3556NI0RE
Session ID 10: CCE3G5LGDREG1AB0LNNQ9JJ1P3
References
More from my site

Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.
No responses yet