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