Why do I use snowflake to generate duplicate id

problem description

for (int i = 0; I < 1000; iPP) {

    //idworker    id
    IdWorker idWorker = new IdWorker(new Random().nextInt(30), 0);
    ....

}

Apr.26,2021

new Random (). NextInt (30) the return value should be 0 to 30.


IdWorker is put inside = =. These two parameters are used in distributed, with a maximum of 961 sets of 31 / 31.
there is only one instance of random IdWorker in a project, and
Random should only use one in the method.
"that is, the seed is used to initialize the value of the random number generator, which always produces the same sequence of random numbers for a specific seed value. General Random random = new Random (); system takes the current time milliseconds as the seed number to achieve random, otherwise write the seed number random number is a fixed value "
-- https://blog.csdn.net/xjk201/.

Menu