RandomUtil
Description
RandomUtil mainly provides a wrapper for the Random object in the JDK. Strictly speaking, the random numbers generated by Java are pseudo-random numbers, so the random results generated by Hutool’s wrapper are also pseudo-random. However, this kind of random result is sufficient for most cases.
Usage
RandomUtil.randomIntto get a random integer within a specified range
For example, if we want to generate a random number between [10, 100), we can use:
int c = RandomUtil.randomInt(10, 100);RandomUtil.randomBytesto generate random bytes, usually used for password or salt generation
byte[] c = RandomUtil.randomBytes(10);RandomUtil.randomEleto randomly get an element from a listRandomUtil.randomEleSetto randomly get a certain number of non-duplicate elements from a list, and return a Set
Set<Integer> set = RandomUtil.randomEleSet(CollUtil.newArrayList(1, 2, 3, 4, 5, 6), 2);RandomUtil.randomStringto get a random string (containing only digits and characters)RandomUtil.randomNumbersto get a string containing only digitsRandomUtil.weightRandomweighted random generator. Pass in objects with weights, and then randomly get objects according to the weights