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

com.github.lsqlebai.utils.UUIDUtils.kt Maven / Gradle / Ivy

There is a newer version: 0.4.1
Show newest version
package com.github.lsqlebai.utils

import java.math.BigInteger
import java.util.*

object UUIDUtils {


    fun uuid(): String {
        val uuid = UUID.randomUUID()
        val str = uuid.toString()
        // 去掉"-"符号
        val temp: String
        temp = str.replace("-".toRegex(), "")
        return temp
    }

    fun sn(): String {
        val uuid = uuid()
        val longSn = BigInteger(uuid, 16).toString()
        return longSn.substring(0, 12)
    }

    fun sn(num: Int): String {
        val uuid = uuid()
        val longSn = BigInteger(uuid, 16).toString()
        return longSn.substring(0, num)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy