You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Andy Kim <An...@mxplay.com> on 2006/09/28 01:35:23 UTC
Random function not really random?
I'm seeing this strange problem (bug?) where the Random function is not
returning a truly random number. In my test scenario I'm running JMeter
against 3 app servers (web1, web2, web3), which I need to hit randomly per
each run of a thread. When I use the __Random function, I get almost double
the amount of hits against web2 compared to web1 or web3. For example (400
threads with a ramp up of 60 seconds, over 2 minutes):
http://web3 - 137 hits
http://web2 - 250 hits
http://web1 - 131 hits
I stripped down my Test Plan to the following and still see the same
behavior:
-> Thread Group
-> Aggregate Report
-> Sample Controller
-> HTTP Request Defaults (where I set Server Name to
web${__Random(1,3,webID)})
-> Sample HTTP Request (Server Name is blank and I
just hit a base URL)
-> Gaussian Timer
-> Browser-derived headers
It seems like a bug to me with the __Random function. It should be pretty
simple for anyone else to reproduce. My workaround will to be use
JavaScript.
Thanks!
-Andy
Re: Random function not really random?
Posted by sebb <se...@gmail.com>.
On 28/09/06, Andy <an...@mxplay.com> wrote:
> Andy Kim <AndyK <at> mxplay.com> writes:
>
> > I get almost double the amount of hits against web2 compared to web1 or web3.
>
> I took a closer look at this and it's a bug with the implementation of Random in
> JMeter. Taking a look at the random function:
>
> http://svn.apache.org/repos/asf/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/Random.java
>
> int rand = (int) Math.round(min + Math.random() * (max - min));
In the 2.2 code it uses long, but is otherwise the same.
> Do you see the problem? If you work out the math the first and last integers
> have exactly 1/2 the probability of being selected as integers in between. I'm
> not sure why JMeter isn't using Java's Random class.
Math.random() does use java.util.Random internally ... seems to be
easier to use in this case.
> But one correct way to do
> it (without the Random class) would be:
>
> int rand = min + (int) (Math.random * (max - min + 1));
>
> I'll see about filing a bug and the checkin.
Thanks - no need for a patch file as the change is so simple.
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
Re: Random function not really random?
Posted by Andy <an...@mxplay.com>.
Andy Kim <AndyK <at> mxplay.com> writes:
> I get almost double the amount of hits against web2 compared to web1 or web3.
I took a closer look at this and it's a bug with the implementation of Random in
JMeter. Taking a look at the random function:
http://svn.apache.org/repos/asf/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/Random.java
int rand = (int) Math.round(min + Math.random() * (max - min));
Do you see the problem? If you work out the math the first and last integers
have exactly 1/2 the probability of being selected as integers in between. I'm
not sure why JMeter isn't using Java's Random class. But one correct way to do
it (without the Random class) would be:
int rand = min + (int) (Math.random * (max - min + 1));
I'll see about filing a bug and the checkin.
-Andy
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org