2012-09-11 92 views
1
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] 

如何生成從列表如何從Jython腳本的列表中隨機獲取值?

我在Jython中寫testscript隨機元。我打電話使用磨牀工具

回答

3

在Python,使用random.choice

import random 
elementinthelist = random.choice(lists.list1) 
+0

它的工作,謝謝:) – srp

0

選擇介於0(含)的隨機整數列表(獨家)的長度的服務。

在常規的Java這種看起來像

Random rand = new Random(); 
int randIx = rand.nextInt(lists.size()); 
Object element = lists.get(randIx); 
+0

謝謝你,但我需要它在Jython和我需要選擇隨機第一個列表元件。 – srp