📄 guidgenerator.java
字号:
/*
* @author : Neelesh
* @Version : 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the Application : GUIDGenerator.java
* Creation/Modification History :
*
* Neelesh 23-Feb-2003 Created
*
*/
package oracle.otnsamples.util;
// Import to generate random number
import java.security.SecureRandom;
/**
* This class uses a combination of current time in milliseconds and a random
* number to generate a unique key.
*
* @author Neelesh
* @version 1.0
*/
public class GUIDGenerator implements KeyGenerator {
// Instance of secure random to generate random numbers
private SecureRandom random;
/**
* Constructor. An instance of SecureRandom is initialized here.
*/
public GUIDGenerator() {
random = new SecureRandom();
System.out.println(random.getProvider().getInfo());
}
/**
* This method returns a key that is unique to a millisecond. The uniqueness
* is increased by appending a random number to the key.
*
* @return <b>String</b> The unique key
*/
public String getKey() {
// Append current time in millis to a hexadecimal representation
// of a random number.
String key =
"" + System.currentTimeMillis() + Long.toHexString(random.nextInt());
return key;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -