Created
February 26, 2022 07:42
-
-
Save joriki/673c6b507c2998aed118e050d2cceaf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.PrintStream; | |
import java.util.Random; | |
public class Question4390837 { | |
final static int a = 2; | |
final static int b = 2; | |
final static int ntrials = 100000000; | |
final static int nbins = 1000; | |
final static Random random = new Random(); | |
public static void main(String [] args) throws IOException { | |
int [] bins = new int [nbins]; | |
double [] A = new double [a]; | |
double [] B = new double [b]; | |
for (int n = 0;n < ntrials;n++) { | |
for (int i = 0;i < a;i++) | |
A [i] = random.nextDouble(); | |
for (int i = 0;i < b;i++) | |
B [i] = random.nextDouble(); | |
double min = 1; | |
for (int i = 0;i < a;i++) | |
for (int j = 0;j < b;j++) | |
min = Math.min(min,Math.abs(A [i] - B [j])); | |
for (int bin = (int) (min * nbins + 1);bin < nbins;bin++) | |
bins [bin]++; | |
} | |
PrintStream out = new PrintStream(new FileOutputStream ("/Users/joriki/math/Question4390837.txt")); | |
for (int bin = 1;bin < nbins;bin++) | |
out.println(bin / (double) nbins + " " + bins [bin] / (double) ntrials); | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment