Thanks:  0
Likes:  0
Dislikes:  0

# Thread: problems with JavaScript code for a normal distribution function

1. ## problems with JavaScript code for a normal distribution function

Hi everyone,

I am currently trying to write a script for a normal distribution function that I will use to model the user delays between transactions, in WebLoad application.
I have actually found a formula for the normal distribution and I wrote a script, but the graphic does not look like a normal distribution curve.
For the formula I got from http://davidmlane.com/hyperstat/norm...tribution.html here is the JavaScript code that I wrote.
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">function normdistrib(totusers, minim, maxim, stddev)
{
// normal distribution of user delays (think time)
// minim - minimal value of delay (the users delay their action for a minimum of miliseconds)
// maxim - maximum value of delay (the users delay their action for maximum of miliseconds)
// stddev - standard deviation in miliseconds
// totusers - the number of users

mysleep = new Array(totusers)
for (i=1; i&lt; totusers; ++i)
{
mean = ((minim + maxim)/2)
epower = -Math.pow((i-mean), 2)/(2*Math.pow(stddev, 2))
p1 = 2 * Math.PI * Math.pow(stddev, 2)
mysleep[i] = (1/Math.sqrt(p1))*Math.pow(Math.E, epower)
InfoMessage(mysleep[i].toString())
}
}</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">In the main script, I called the function with the following parameters:
normdistrib(100,18000,25000,3000)
But the curve that results from the 'mysleep' array above is rather linear that normal distribution alike.

Does anyone know what I do wrong?

Thanks, Ioana

2. ## Re: problems with JavaScript code for a normal distribution function

Interesting approach.
Why are you going through this effort? Is it not sufficient to identify the average user delay or perhaps use the average +/- some factor?

Discussions on the topic of user time, think time, user latency, etc., would indicate this is perhaps overkill on your part.

3. ## Re: problems with JavaScript code for a normal distribution function

Pretty darned slick, though. I was once in search of the same thing (but didn't find it) when I was trying to spiff up a college assignment involving "the sleeping barber" scenario.

4. ## Re: problems with JavaScript code for a normal distribution function

Hi Ioana,

I may be reading your question wrong but I think what you want to create is a javascript program that will generate random numbers (think time, wait time, etc...) with a normal distribution. The site and formulas you use are useful in computing the normal distribution characteristics from a set of numbers. What you really want is a javascript program that will generate these numbers for you.

Here is a link that has the javascript source code to generate the random numbers (normally distributed).

http://javascript.internet.com/calcu...tribution.html

Good luck.

5. ## Re: problems with JavaScript code for a normal distribution function

Hello!,

This is exactly what I was looking for.

Thanks a lot.
Ioana

Originally posted by TFMiller:
Hi Ioana,

I may be reading your question wrong but I think what you want to create is a javascript program that will generate random numbers (think time, wait time, etc...) with a normal distribution. The site and formulas you use are useful in computing the normal distribution characteristics from a set of numbers. What you really want is a javascript program that will generate these numbers for you.

Here is a link that has the javascript source code to generate the random numbers (normally distributed).

http://javascript.internet.com/calcu...tribution.html

Good luck.
<font size="2" face="Verdana, Arial, Helvetica">

6. ## Re: problems with JavaScript code for a normal distribution function

Just out of interest, are you the same person as "IoanaC"? Apart from the similarity of handles, (both of) you seem to have an unusual interest in "things mathematical."

7. ## Re: problems with JavaScript code for a normal distribution function

Hello!

No, I am not the same person as "IoanaC".
The similarity may come from the fact that "Ioana" is a Romanian first name.
It seems we are two, here, in these forums.
My interest in 'things mathematical' comes from the series of articles "User Experience, not Metrics Series" written by Scott Barber.
I wanted to see if I can apply it using WebLoad.

Although, it is funny the coincidence that you have noticed.

Ioana S

Originally posted by Peter Ruscoe:
Just out of interest, are you the same person as "IoanaC"? Apart from the similarity of handles, (both of) you seem to have an unusual interest in "things mathematical."
<font size="2" face="Verdana, Arial, Helvetica">

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.40 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.