Encapsulates various tool classes that generate a unique ID algorithm

Source: Internet
Author: User
Tags uuid

/**
* Copyright (c) 2005-2012 springside.org.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
Package com.minxinloan.common.utils;

Import Java.security.SecureRandom;
Import Java.util.UUID;

/**
* Encapsulates various tool classes that generate a unique ID algorithm.
* @author Calvin
* @version 2013-01-15
*/
public class Identities {

private static SecureRandom random = new SecureRandom ();

/**
* Encapsulates the UUID that comes with the JDK, generated by random numbers, and split in the middle.
*/
public static String uuid () {
Return Uuid.randomuuid (). toString ();
}

/**
* Encapsulates the JDK's own uuid, generated by random numbers, middle none-split.
*/
public static String Uuid2 () {
Return Uuid.randomuuid (). toString (). ReplaceAll ("-", "" ");
}

/**
* Use SecureRandom to randomly generate long.
*/
public static long Randomlong () {
Return Math.Abs (Random.nextlong ());
}

/**
* SecureRandom randomly generated bytes based on Base62 encoding.
*/
public static String randomBase62 (int length) {
byte[] randombytes = new Byte[length];
Random.nextbytes (randombytes);
Return encodes.encodebase62 (randombytes);
}
}

Encapsulates various tool classes that generate a unique ID algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.