All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.tio.utils.snowflake.SnowflakeIdUtils Maven / Gradle / Ivy

There is a newer version: 3.7.3.v202400213-RELEASE
Show newest version
package com.litongjava.tio.utils.snowflake;

import java.util.Random;

public class SnowflakeIdUtils {

  // 单例的 SnowflakeIdGenerator 实例
  private static final SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(randomInt(1, 30),
      randomInt(1, 30));

  public static long id() {
    return snowflakeIdGenerator.generateId();
  }

  public static int randomInt(int min, int max) {
    Random random = new Random();
    int randomNumber = random.nextInt(max - min + 1) + min;
    return randomNumber;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy