Switch to full style
General Java code examples
Post a reply

Generating Random Number in java

Tue Nov 11, 2008 11:52 pm

java code
import java.util.*;

public class GenerateRandomNumber{
public static void main(String[] args){
Random rand = new Random();
int num = rand.nextInt(10);
System.out.println("Generated Random Number between 0 to 10 is : " + num);
int numNoRange = rand.nextInt();
System.out.println("Generated Random Number
without specifying any range is : " + numNoRange);
}
}


The Random class of java.util package can be used to generate a random number in the range which can be specified. If you don't mention the range value then program will generate any random number for your.



Post a reply
  Related Posts  to : Generating Random Number in java
 Weka java code for Random Forest Cross Validation     -  
 Cost Sensitive Classifier Random Forest Java in weka     -  
 Generating Tables from XML by php     -  
 generating examination timetable     -  
 Get BIOS Serial Number in java     -  
 convert integer number to octal,hexadecimal number systems     -  
 convert octal number to decimal number     -  
 convert decimal number to octal number     -  
 php Random image     -  
 Random to File     -  

Topic Tags

Java Algorithms