Created
February 8, 2024 08:26
-
-
Save joriki/4dd7f405bf4b7967c026f335350e8cf1 to your computer and use it in GitHub Desktop.
Estimate the probability of a certain inequality being satisfied for uniformly distributed random variables; see https://math.stackexchange.com/questions/4859023.
This file contains hidden or 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
public class Question4859023 { | |
final static long ntrials = 100000000L; | |
public static void main(String [] args) { | |
long count = 0; | |
for (long n = 0;n < ntrials;n++) { | |
double x1 = 5 * Math.random(); | |
double x2 = 5 * Math.random(); | |
double y1 = 5 * Math.random(); | |
double y2 = 5 * Math.random(); | |
if ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) > (x2 + x1) * (x2 + x1)) | |
count++; | |
} | |
System.out.println(count / (double) ntrials); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment