/** * Sets the number of random characters that will be appended to the * {@link #createDigest(String) digest}. When it is set to 0, nothing * will be appended to the digest. Otherwise, a random string will be * generated (containing only letters and digits) and appended to the * digest. * <p> * Random digest chars is a <b>unique</b> key per one VM! * This key is initialized only once. * This is useful to automatically expire any cache that browsers may have in * JS and CSS files, so that changes in those files will be downloaded by the * browser. */ public void setRandomDigestChars(final int randomDigestChars) { this.randomDigestChars = randomDigestChars; if (randomDigestChars == 0) { uniqueDigestKey = null; } else { uniqueDigestKey = new RandomString().randomAlphaNumeric(randomDigestChars); } }
@Test void testRepeatableSequence() { RandomString randomString = new RandomString(123); String rnd = randomString.randomAlpha(2); RandomString randomString2 = new RandomString(123); String rnd2 = randomString2.randomAlpha(2); assertEquals(rnd, rnd2); }
@Test void testRandomBase64() { long iter = 10000; RandomString randomString = new RandomString(); while (iter-->0) { String base64 = randomString.randomBase64(10); try { Base64.decodeToString(base64); } catch (Exception e) { fail(e.getMessage()); } } } }
/** * Sets the number of random characters that will be appended to the * {@link #createDigest(String) digest}. When it is set to 0, nothing * will be appended to the digest. Otherwise, a random string will be * generated (containing only letters and digits) and appended to the * digest. * <p> * Random digest chars is a <b>unique</b> key per one VM! * This key is initialized only once. * This is useful to automatically expire any cache that browsers may have in * JS and CSS files, so that changes in those files will be downloaded by the * browser. */ public void setRandomDigestChars(final int randomDigestChars) { this.randomDigestChars = randomDigestChars; if (randomDigestChars == 0) { uniqueDigestKey = null; } else { uniqueDigestKey = new RandomString().randomAlphaNumeric(randomDigestChars); } }