Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;

import java.util.UUID;

public class Main {
    public static long generateMpid() {
        while (true) {
            long id = hashFnv1A(UUID.randomUUID().toString().getBytes()).longValue();
            if (id != 0) {
                return id;
            }
        }
    }

    public static BigInteger hashFnv1A(byte[] data) {
        final BigInteger INIT64 = new BigInteger("cbf29ce484222325", 16);
        final BigInteger PRIME64 = new BigInteger("100000001b3", 16);
        final BigInteger MOD64 = new BigInteger("2").pow(64);

        BigInteger hash = INIT64;

        for (byte b : data) {
            hash = hash.xor(BigInteger.valueOf((int) b & 0xff));
            hash = hash.multiply(PRIME64).mod(MOD64);
        }

        return hash;
    }
}