"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by marc weber:
A call to Thread.sleep(long milliseconds) is the easiest way to create "pauses."
To me, the question is about these random intervals. I understand they should average 60 seconds (60000 milliseconds), but what should their range and distribution be?
If you're okay with a uniform distribution, then you can use Math.random(). For example, if you wanted the values to range between 50 and 70 seconds (a span of 20 seconds), you could use something like...
int secs = (int)(Math.random() * 20) + 50;
But if you need to work with a normal ("bell curve") distribution, then you might look at the nextGaussian() method in the java.util.Random class.
[ April 07, 2005: Message edited by: marc weber ]
Originally posted by George Lin:
...I think you are an expert of this field...
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by marc weber:
Thank you, but I am not an expert.
The API for java.util.Random indicates that nextGaussian() returns a pseudorandom double from a normal distribution with mean 0.0 and standard deviation 1.0.
So to refine the variance, I expect that you would multiply the returned value by a new standard deviation. Then, to refine the mean, you would simply add the new mean.
For example, if you wanted random numbers from a normal distribution with a mean of 45.67 and a standard deviation of 3.4, you would use something like...
Random rGen = new Random();
double normRand = (rGen.nextGaussian() * 3.4) + 45.67;
I put the above code in a small test program, and the output looks right. But this is actually the first time I've ever used nextGaussian(), so perhaps a real expert can confirm...?
Ref: http://java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Originally posted by marc weber:
If you search the internet for "normal distribution," "standard deviation," etc. I'm sure you'll find plenty of material. Much of it will involve Calculus, but you should be able to find some lessintensive material as well.
You might start here:
http://en.wikipedia.org/wiki/Normal_distribution
He baked a muffin that stole my car! And this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filleradvertising
