Search code examples
javapythonjythongrinder

How do I get a value randomly from a list in Jython script?


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


Solution

  • In Python, use random.choice:

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