Importing the random package in python 2.5

LegacyForumLegacyForum Posts: 1,669 ✭✭
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



  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    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.
Sign In or Register to comment.