Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to generate random double numbers in JMeter?

I tried to use the Random in the config element where i have defined the

Minimum value: 47.9999  (RND1)
Maximum value: 30.9999  (RND2)

Then in the selected Prepared Selected Statement i placed this values:

Parameter values: ${RND1},${RND1},${RND2}
Parameter types: DOUBLE,DOUBLE,DOUBLE

But it seems not work, because i receive an error:

Response message: java.sql.SQLException: Cannot convert class java.lang.String to SQL type requested due to java.lang.NumberFormatException - For input string: "${RND1}"

share|improve this question

1 Answer 1

Looks like ${RND1} is not expanded to it's value in your JDBC Request because it wasn't initialized Random Variable config item - because the last one is to generate only integer values (as well as jmeter's __Random function).

To generate random double values in defined range you can use schema like below:

1. Define MIN and MAX range values as variables in User Defined Variables

RND1    37.9999
RND2    41.9999
2. Generate random double value in range RND1..RND2 using e.g. Beanshell Sampler:

  • Parameters: ${RND1},${RND2}
  • Script (java code):
import java.util.*;

String [] params = Parameters.split(",");

double rangeMin = Double.valueOf(params[0]);
double rangeMax = Double.valueOf(params[1]);
Random r = new Random();
double randomValue = rangeMin + (rangeMax - rangeMin) * r.nextDouble();

vars.put("RND",randomValue.toString());

//System.out.println(randomValue);

Adding Debug Sampler, with Jmeter variables = true let you see generated values for debugging purposes.

3. Refer generated random value as ${RND} for further use (in JDBC Request in your case)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.