File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
src/main/java/com/ydyno/config Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 2020import org .springframework .boot .context .properties .ConfigurationProperties ;
2121import org .springframework .context .annotation .Configuration ;
2222import org .springframework .stereotype .Component ;
23- import java .util .Collections ;
2423import java .util .List ;
24+ import java .util .Random ;
2525
2626/**
2727 * @author Zheng Jie
@@ -66,11 +66,14 @@ public class MyAiConfig {
6666 public String getApiKey () {
6767 // 转为 List
6868 List <String > keyList = ListUtil .toList (keys .split ("," ));
69- // 打乱顺序
70- if (keyList .size () > 1 ){
71- Collections .shuffle (keyList );
69+ if (keyList .size () == 1 ){
70+ return keyList .get (0 );
7271 }
72+ // 打乱顺序
73+ Random random = new Random ();
74+ // 获取0~list.size()之间的随机数
75+ int index = random .nextInt (keyList .size ());
7376 // 获取一个 key
74- return keyList .get (0 );
77+ return keyList .get (index );
7578 }
7679}
You can’t perform that action at this time.
0 commit comments