Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Importing the random package in python 2.5

LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest

I am trying to import and use the Random module within Python and am having a hard time getting SOATest to properly use the python method that I have defined. The code is as follows


from com.parasoft.api import *
from soaptest.api import *
from java.util import *
from java.lang import *
from random import *

def pickRandomValue(input, context):
value = SOAPUtil.getStringFromObject (input)
tokenizer = StringTokenizer(value, ",")
list = ArrayList()
while (tokenizer.hasMoreTokens()):

random.seed ()
randIndex = random.randint (0,list.size()-1)
# randIndex = int(Math.ceil(Math.random() * (list.size()-1)))
return SOAPUtil.getXMLFromString([list.get(randIndex)])

I have Python 2.5 installed and have changed my Python.path and Python.home to point at my python installation directory. When I have SOATest evaluate this code the method does not show up in the drop down box to choose from. Any help would be greatly appreciated



  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Currently, the advised practice is to use the java implementation of Random. However, if you must use the python 2.5 random module, then you will have to alter the SOAtest execution target to "soatest.exe -J-Dpython.home="C:\python_install_dir". The "from random import *" should work then.