Skip to content

Instantly share code, notes, and snippets.

@altimmons
Created September 15, 2019 04:46
Show Gist options
  • Save altimmons/7532823bb3cf7f95a63d145f6017063e to your computer and use it in GitHub Desktop.
Save altimmons/7532823bb3cf7f95a63d145f6017063e to your computer and use it in GitHub Desktop.
double x1 = 1.0, x2 = 10.0; //or float x1 = 1.0f, x2 =2.0f
double f = Math.random()/Math.nextDown(1.0);
double x = x1*(1.0 - f) + x2*f;
//test code
int c = 0;
while(c< 20) {
float x1 = 1.0f, x2 = 10.0f;
double f = Math.random() / Math.nextDown( 1.0 );
double x = x1 * ( 1.0 - f ) + x2 * f;
System.out.printf( "%d) %f\n" , (c + 1), x );
c++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment