Generate Random Series in java

import java.util.Random;

/** Generate random integers in a certain range. */
public final class RandomRange {

public static final void main(String… aArgs){
log(“Generating random integers in the range 1..10.”);

long START = 5412;
long END = 5422;
Random random = new Random();
for (int idx = 5412; idx 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("Generated : "+"984238"+idx +" Value = " + randomNumber);
}

private static void log(String aMessage){
System.out.println(aMessage);
}
}

About ashokabhat

I am a C,C ,JAVA,Adobe Flex,.NET Programmer Currently working as a Software Developer
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s