티스토리 뷰
728x90
package util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
import java.util.Random;
public class RandomUtils {
private static class SHA256 {
public static String encrypt(String text) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
md.update(text.getBytes());
return bytesToHex(md.digest());
}
private static String bytesToHex(byte[] bytes) {
StringBuilder builder = new StringBuilder();
for (byte b : bytes) {
builder.append(String.format("%02x", b));
}
return builder.toString();
}
}
private static final Random random = new Random();
public static Object random(String type) {
switch (type) {
case "string":
return SHA256.encrypt(String.valueOf(random.nextDouble()));
case "integer":
return random.nextInt();
case "long":
return random.nextLong();
case "double":
return random.nextDouble();
default:
return null;
}
}
public static Map<String, Object> random(Map<String, Object> map) {
for (String k : map.keySet()) {
map.put(k, random((String) map.get(k)));
}
return map;
}
}
https://psychoria.tistory.com/761
[Java] 자바 난수 (Random Number) 생성 방법
난수(랜덤 넘버) 생성은 프로그래밍에서 자주 사용되는 기능입니다. 확률을 적용하기 위해 난수를 사용할 수 있습니다. 로또 번호를 생성하는 프로그램을 작성할 때 난수 생성 방법을 활용할 수
psychoria.tistory.com
728x90
'공부' 카테고리의 다른 글
[MySQL] Types (0) | 2022.01.10 |
---|---|
[Java] JSON Object (0) | 2022.01.10 |
[Java] RandomUtils (0) | 2022.01.10 |
[MySQL] create user (0) | 2022.01.10 |
[Java] SHA256 (0) | 2022.01.10 |
[Java] resource (0) | 2022.01.10 |
댓글
250x250
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- 142,688
- Today
- 14
- Yesterday
- 219
TAG
- 개리마커스
- 클루지
- 연애학개론
- Bot
- follower
- wlw
- 어떻게 능력을 보여줄 것인가?
- 인스타그램
- 김달
- COUNT
- Kluge
- 유투브
- 책그림
- 팔로워 수 세기
- 메디파크 내과 전문의 의학박사 김영수