Created
July 24, 2018 17:56
-
-
Save paullewallencom/fe742a67b2a84c7015250331caa9d7ed to your computer and use it in GitHub Desktop.
Prints 'N' numbers with a range between 'lo' and 'hi'.
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
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