检查UUID字符串是否为Prime

Hay*_*121 5 java uuid

我创建了一个创建128位UUID字符串的方法,我现在想检查这是否是素数.我不能将字符串放入int中,因为它太大了.任何人都可以建议我如何检查?

这是我用于创建UUID的代码

    public static String uuid()
    {
        UUID uuid = UUID.randomUUID();
        long hi = uuid.getMostSignificantBits();
        long lo = uuid.getLeastSignificantBits();
        byte[] bytes = ByteBuffer.allocate(16).putLong(hi).putLong(lo).array();
        BigInteger big = new BigInteger(bytes);
        String numericUuid = big.toString().replace('-','1'); // just in case
        //System.out.println(numericUuid);
        return(numericUuid);
    }
Run Code Online (Sandbox Code Playgroud)

Jos*_*osh 2

您可以使用 BigInteger 的 isProbablePrime:

http://www.tutorialspoint.com/java/math/biginteger_isprobableprime.htm

如果您传递一个高确定性参数(例如 100),那么如果返回 true,则它实际上是素数的概率非常接近 1。