Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.UUID;

public class Main {
    public static byte[] randomUUID() {
        long n;
        byte[] result;
        UUID uuid;

        result = new byte[16];
        uuid = UUID.randomUUID();

        n = uuid.getMostSignificantBits();

        result[0] = (byte) (n >> 56 & 0xff);
        result[1] = (byte) (n >> 48 & 0xff);
        result[2] = (byte) (n >> 40 & 0xff);
        result[3] = (byte) (n >> 32 & 0xff);
        result[4] = (byte) (n >> 24 & 0xff);
        result[5] = (byte) (n >> 16 & 0xff);
        result[6] = (byte) (n >> 8 & 0xff);
        result[7] = (byte) (n & 0xff);

        n = uuid.getLeastSignificantBits();

        result[8] = (byte) (n >> 56 & 0xff);
        result[9] = (byte) (n >> 48 & 0xff);
        result[10] = (byte) (n >> 40 & 0xff);
        result[11] = (byte) (n >> 32 & 0xff);
        result[12] = (byte) (n >> 24 & 0xff);
        result[13] = (byte) (n >> 16 & 0xff);
        result[14] = (byte) (n >> 8 & 0xff);
        result[15] = (byte) (n & 0xff);

        return result;
    }
}