变量mynation从列表{"china", "US", "UK"}中随机取值
String[] nation = new String[]{"china", "US", "UK"};
Random random = new Random();
int i = random.nextInt(nation.length);
vars.put("mynation",nation[i]);
在需要使用的 地方直接 ${mynation} 引用即可
如果要设置两个变量且变量值随机但不重复,可以通过两个列表放置不同值实现
String[] nation = new String[]{"china", "US", "UK"};
Random random = new Random();
int i = random.nextInt(nation.length);
vars.put("mynation",nation[i]); String[] num = new String[]{"8", "2", "1","7"};
Random r = new Random();
int j = r.nextInt(num.length);
vars.put("anum",num[j]);