# How I generate the postive total mean from this java code.It geneate negative mean approaches to infinity

• July 17th, 2014, 04:45 AM
bilal.aime@gmail.com
How I generate the postive total mean from this java code.It geneate negative mean approaches to infinity
Quote:

First, it generates ten random numbers from normal distribution and calculates the mean of ten numbers and stores this in an ArrayList. Similarly, it does this for ten lac times. Then, it gives the total mean of ten lac values which is a positive value like this: 0.000142. But it generates negative values as it approaches to infinity. I want positive values... How I will achieve this task? Someone tell me, thanks
Code :

```package statistics;   import java.util.ArrayList; import java.util.Iterator; import java.util.Random; import org.apache.commons.math3.distribution.NormalDistribution; import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;   public class NewClass {   public static void main(String[] args) {   double mean=0.0; ArrayList store_mean=new ArrayList(); Iterator it; DescriptiveStatistics stats = new DescriptiveStatistics(); Random gaussian = new Random(); for(int i=1; i<=1000000; i++) {   for (int idx = 1; idx <= 10; ++idx) { // System.out.println("Generated : " + gaussian.nextGaussian()); stats.addValue(gaussian.nextGaussian());     } mean = stats.getMean(); stats.clear(); store_mean.add(mean); } it=store_mean.iterator(); while(it.hasNext()) { stats.addValue((double) it.next());   } mean=stats.getMean();     System.out.println("Total Mean="+mean);           }```
• July 17th, 2014, 05:02 AM
Cornix
Re: How I generate the postive total mean from this java code.It geneate negative mean approaches to infinity
Might it be that you get a value overflow for the range of valid integer values?