Explain java.util.random package, JAVA Programming

Explain java.util.Random package?

The java.util.Random class permits you to create objects which generates pseudo-random numbers along with uniform or gaussian distributions according to a linear congruential formula along with a 48-bit seed.

The algorithm used is excellent sufficient for single-player, no-money games. I wouldn't use it for cryptography.
You can select the seed or you can let Java pick one based on the current time.

Random r = new Random(109876L);
int i = r.nextInt();
int j = r.nextInt();
long l = r.nextLong();
float f = r.nextFloat();
double d = r.nextDouble();
int k = r.nextGaussian();
The nextInt(), nextLong(), and nextBytes() techniques all cover their respective ranges along with equal likelihood. For example, to simulate a six-sided die; in which is to produces a random integer among 1 and 6, you might write
Random r = new Random();
int die = r.nextInt();
die = Math.abs(die);
die = die % 6;
die += 1;
System.out.println(die);

The nextGaussian() method returns a pseudo-random, Gaussian distributed, double value with mean 0.0 and standard deviation 1.0.
The nextBytes() method fills a byte[] array with random bytes. For example,

byte[] ba = new byte[1024];
Random r = new Random();
r.nextBytes(ba);
for (int i = 0; i < ba.length; i++) {
System.out.println(ba[i]);

Posted Date: 5/16/2013 2:49:11 AM | Location : United States







Related Discussions:- Explain java.util.random package, Assignment Help, Ask Question on Explain java.util.random package, Get Answer, Expert's Help, Explain java.util.random package Discussions

Write discussion on Explain java.util.random package
Your posts are moderated
Related Questions

Explain Vector or Object-Oriented Graphics? The representation of graphical objects, like as lines, circles, arcs, and rectangles, along with mathematical formulas. This techni


What is spreadsheet? List any two jobs that it can do? A spreadsheet is a grid which organizes data within columns and rows. Spreadsheets form it simple to display information,

ActionServlet performs the role of Controller: ? Process user requests ? Verify what the user is trying to achieve according to the request ? Pull data from the model (if

Describe the final keyword ? The final keyword is used in various different contexts as a modifier meaning in which what it modifies cannot be changed in a few sense. final c

How can you justify that a DBMS is better to use than Flat-file database? A DBMS takes care of the storage, retrieval, and management of large data sets on a Database. It give

what is thread synchronization

Hi i need help creating a small program that basically asks the user how many numbers hes going to use and then ask for those numbers and see which is the biggest and the smaller