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]

How do i generate the random element from the list

I am writing a testscript in Jython. I am calling the service using Grinder tool

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
srp
  • 521
  • 11
  • 22

2 Answers2

3

In Python, use random.choice:

import random
elementinthelist = random.choice(lists.list1)
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
0

Choose a random integer between 0 (inclusive) and the length of the list (exclusive).

In regular Java this would look like

Random rand = new Random();
int randIx = rand.nextInt(lists.size());
Object element = lists.get(randIx);
matt b
  • 138,234
  • 66
  • 282
  • 345
  • thank you, but i need it in jython, and i need to select the first list with random element. – srp Sep 11 '12 at 12:53