testingjmeterperformance-testing

JMeter make random number return float


I have this:

  "latitude": ${__Random(-85,85)},
  "longitude": ${__Random(-180,180)},

I would like to have this:

  "latitude": ${__Random(42.06,42.08)},
  "longitude": ${__Random(20.02,20.04)},

but it does not work. How to change it to have a random number between 42.06 - 42.08 and 20.02 and 20.04 ?


Solution

  • If you need that limited random values just use static prefix like 20.0 and call __Random() function to generate the postfix, like:

    "latitude": 42.0${__Random(6,8,)},
    "longitude": 20.0${__Random(2,4,)},
    

    If you're looking for a way to generate fully random latitude and longitude values I would recommend switching to __javaScript() function like:

    "latitude": ${__javaScript((Math.random() * (180) - 90).toFixed(2) * 1,)},
    "longitude": ${__javaScript((Math.random() * (360) - 180).toFixed(2) * 1,)},
    

    See How to Use JMeter Functions posts series for more information on above and other JMeter Functions.