Java 如何从Jython脚本中的列表中随机获取值?

Java 如何从Jython脚本中的列表中随机获取值?,java,python,jython,grinder,Java,Python,Jython,Grinder,如何从列表中生成随机元素 我正在用Jython编写一个测试脚本。我正在使用Grinder tool调用服务在0(包括)和列表长度(不包括)之间选择一个随机整数 在常规Java中,这看起来像 lists = portTest.lists(arg1, arg2) // this returns the lists from webservice in java // public String[] list1; // public String[] list2;public Strin

如何从列表中生成随机元素


我正在用Jython编写一个测试脚本。我正在使用Grinder tool调用服务

在0(包括)和列表长度(不包括)之间选择一个随机整数

在常规Java中,这看起来像

lists = portTest.lists(arg1, arg2) 

// this returns the lists from webservice in java  
//  public String[] list1; 
//  public String[] list2;public String[] list3;

// i want to get the random element in the list,
// not the first, second or any selected item. 
elementinthelist = lists.list1[0]
在Python中,使用:


谢谢,但是我需要它在jython中,我需要选择第一个带有随机元素的列表。
Random rand = new Random();
int randIx = rand.nextInt(lists.size());
Object element = lists.get(randIx);
import random
elementinthelist = random.choice(lists.list1)