Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Sailors{
- static int N=10000; //number of sailors
- static double [] sls = new double[N];//actual sailor coordinates
- static double step = 1.;//step size
- static Random rnd = new Random();
- static int currenttime=0;
- static void makestep(){
- for(int i=0;i<N;i++){
- if(rnd.nextDouble()<0.5)
- sls[i]+=step;
- else
- sls[i]-=step;
- }
- }
- static void statistics(){
- double sum=0; //sum of coordinates
- double sum2=0;//sum of coordinate squares
- for(int i=0;i<N;i++){
- sum+=sls[i];
- sum2+=sls[i]*sls[i];
- }
- double mean = sum/N;
- double meansquare = sum2/N;
- System.out.println("Time "+currenttime+" Mean "+mean+" meansquare "+meansquare+" rooted meansquare "+Math.sqrt(meansquare));
- }
- public static void main(String[] args){
- for(int i=1;i<100;i++){
- currenttime=i;
- makestep();
- statistics();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement