Generation of 8-bit non-repeating random codes using timestamps

Source: Internet
Author: User

Generation of 8-bit non-repeating random codes using timestampsmore 0Timestamp Java 16 binary random Code

The timestamp is the total number of seconds from January 1, 1970 (00:00:00 GMT) to the current time. Because time is not duplicated, it is convenient to use time to generate a string of distinct IDs or strings.

Idea: Get the timestamp of the current time , and then convert to 16 binary.

The
resulting results are as follows:

Current time: Mon May 14:47:51 CST 2013
Generate 8-bit random code: 9ca52f20

Related code:
ImportJava.Util.Date; Public Class Test { Public Static voidMain(String[]Args) { TODO auto-generated Method Stub System.Out.println(New Date()); System.Out.println(Tohex(New Date (). gettime } /** * get 8-bit non-repeating random code (convert current timestamp to 16 binary) * @author Shelwee * @param time * @return */ public  string Tohex ( Long Time) { return Span class= "Typ" >integer. ((inttime  }}       /span>                 
Original address: Use timestamp to generate 8-bit non-repeating random code, thank the original author to share.

Generation of 8-bit non-repeating random codes using timestamps

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.