Skip to content

Instantly share code, notes, and snippets.

@froop
Created February 16, 2012 11:41
Show Gist options
  • Save froop/1844275 to your computer and use it in GitHub Desktop.
Save froop/1844275 to your computer and use it in GitHub Desktop.
[Java] ランダム文字列生成(仮パスワード用)
import org.apache.commons.lang3.RandomStringUtils;
@Test public void testRandomStringUtils() {
String random1 = RandomStringUtils.randomAlphanumeric(10);
String random2 = RandomStringUtils.randomAlphanumeric(10);
assertTrue(random1, random1.matches("[a-zA-Z0-9]{10}"));
assertTrue(random2, random2.matches("[a-zA-Z0-9]{10}"));
assertFalse(random1.equals(random2));
System.out.println(random1);
System.out.println(random2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment