Random

    [JAVA] 랜덤 퍼센트 계산하는 클래스(?)

    게임이나 뭐 확률 관련된 개발을 하다보면 뭔가 퍼센트로 어떤 동작이 실행됐냐 안됐냐를 확인하고 싶을때가 있다 input : percentoutput : true / false ex)input : 0.8foutput : true 이런식으로 말이다. 이럴때!! 쓰는 간단한 클래스 public class ChanceSupport { public static boolean percent(double percent) { return percent > ThreadLocalRandom.current().nextDouble(0, 1); } } } double로 받은 percent 변수가 랜덤으로 뽑은 double 변수와 비교해서 그보다 작은지를 확인한다 ex)랜덤으로 뽑은 값 : 0~1퍼센트로 지정한 값 : 0.8 i..