I have this code that if it does is generate random numbers in a range that I choose. The problem I have is that if they see the line of for, I supposedly have to generate 10000 random numbers, but this only makes me 6668. If I put a less than that amount, the code works fine. What's going on? Eclipse has some sort of character limit? Thank you very much!
Greetings!
import java.util.Random;
public static final void main(String... aArgs){
log("Generating random integers in the range 1..10.");
int START = 2000000 ;
int END = 8999999 ;
Random random = new Random();
for (int idx = 1; idx <= 10000; ++idx){
showRandomInteger(START, END, random);
}
log("Done.");
}
private static void showRandomInteger(int aStart, int aEnd, Random aRandom){
if (aStart > aEnd) {
throw new IllegalArgumentException("Start cannot exceed End.");
}
//get the range, casting to long to avoid overflow problems
long range = (long)aEnd - (long)aStart + 1;
// compute a fraction of the range, 0 <= frac < range
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart);
log("351" + randomNumber);
}
private static void log(String aMessage){
System.out.println(aMessage);
}
}
Yes, eclipse has a character limit on the console, but you can expand it or cancel the limit altogether.
In Eclipse's preferences, go to Run/Debug
, then to Console
. You see a checkbox "Limit console output". You can uncheck it, or you can change the Console buffer size
.
I'm referring to Eclipse Luna.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.