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;

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();
for (int i = 0; i < ba.length; 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
Need to develop Chat application for j2me and I want Image Processing code Project Description: We want a chat application for a community website. Image processing and co

Operator Functionality E x ample/Explanation = Sets one value equal to another counter=0  Sets the counter to equivale

Illustrate the parser method The below table summarizes the parser methods available to a java programmer.

I want android expert Project Description: I have too many android project pending anyone who will start work right away, with me will bid here , only bid if you can work rig

program t ofind area under the curve y=f(x) between x=a and x=b integrate y=f(x) between the limits a and b

i''m trying to make a code to make the simon says game and i can''t figure it outt

Explain The Methods of java.lang.Object? java.lang.Object gives a number of methods that are general to all objects. toString() is the most general such method. Because the def

Describe Interfaces in java langauge? Interfaces are the further level of abstraction. An interface is like a class along with nothing but abstract methods and final, static fi

Problem 1 A savings account object holds a non-negative balance, and provides deposit(k ) and withdraw(k ) methods, where deposit(k ) adds k to the balance, and withdraw(k ) subtra

Define : Authorization is the process by which a program calculates whether a given identity is permitted to access a source such as an application component or a file. Now that y