Commit 77a6ee36d8ff49c7a0df4741e320fc11aae03f9f

Authored by 王明元
1 parent cce44df3

2023年5月31日12:55:53 获取did方式改为随机获取一个

src/main/java/cn/fw/freya/service/crawl/impl/Common.java
... ... @@ -41,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
41 41 import org.springframework.util.CollectionUtils;
42 42  
43 43 import java.io.IOException;
  44 +import java.security.NoSuchAlgorithmException;
  45 +import java.security.SecureRandom;
44 46 import java.util.*;
45 47 import java.util.logging.Level;
46 48 import java.util.stream.Collectors;
... ... @@ -365,9 +367,21 @@ public class Common {
365 367 .list();
366 368 if (did.isEmpty())
367 369 return null;
368   - Random random = new Random();
369   - int index = random.nextInt(did.size() - 1);
370   - return did.get(index).getValue();
  370 + if (Objects.equals(did.size(), 1))
  371 + return did.get(0).getValue();
  372 + try {
  373 + Random random = SecureRandom.getInstanceStrong();
  374 + int index = random.nextInt(did.size() - 1);
  375 + return did.get(index).getValue();
  376 + } catch (Exception e) {
  377 + return null;
  378 + }
  379 + }
  380 +
  381 + public static void main(String[] args) throws NoSuchAlgorithmException {
  382 + Random random = SecureRandom.getInstanceStrong();
  383 + int index = random.nextInt(5 - 1);
  384 + System.out.println(index);
371 385 }
372 386  
373 387 /**
... ...