Skip to content

Instantly share code, notes, and snippets.

@paullewallencom
Created July 24, 2018 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paullewallencom/fe742a67b2a84c7015250331caa9d7ed to your computer and use it in GitHub Desktop.
Save paullewallencom/fe742a67b2a84c7015250331caa9d7ed to your computer and use it in GitHub Desktop.
Prints 'N' numbers with a range between 'lo' and 'hi'.
public class RandomSeq
{
private RandomSeq() { }
public static void main( String[] args )
{
int n = Integer.parseInt( args[0] );
if ( args.length == 1 )
{
for ( int i = 0; i < n; i++ )
{
double x = StdRandom.uniform();
StdOut.println( x );
}
} else if ( args.length == 3 ) {
double lo = Double.parseDouble( args[1] );
double hi = Double.parseDouble( args[2] );
for ( int i = 0; i < n; i++ )
{
double x = StdRandom.uniform( lo, hi );
StdOut.printf( "%.2f\n", x );
}
} else {
throw new IllegalArgumentException( "Invalid number of arguments" );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment