Explain java.util.random package, JAVA Programming

Assignment Help:

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++) {

Related Discussions:- Explain java.util.random package

Java , what is thread synchronization

what is thread synchronization

Web application using javascript-xml and css, Journal of how you came to AU...

Journal of how you came to AUB Write a web application using JavaScript, XML and CSS that contains a journal of major events and places on your journey to Bond University. The

Convert psd to android, Convert PSD to Android (UI only, no database) Pr...

Convert PSD to Android (UI only, no database) Project Description: I want someone highly proficient in Photoshop and Android SDK to change series of PSD files into live Andro

What are checked and unchecked exception, What are Checked and UnChecked Ex...

What are Checked and UnChecked Exception? A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making a

Write code in javascript language to show the odd numbers, Write code in Ja...

Write code in JavaScript language to show the odd numbers among 20 to 100 using FOR statement. Note: No requirement to write whole HTML program. Just JavaScript code of need p

Java pass arguments by value or reference, Does Java pass arguments by valu...

Does Java pass arguments by value or reference? Ans) Pass by value. 1. When passing primitives, it going a copy of the variable to the method. Any change made in the method d

Oop, creating a point of sale

creating a point of sale

Define high-level thread states?, The state chart diagram given below defin...

The state chart diagram given below defines the thread states.     1.      Runnable - waiting for its turn to be picked for performing by the thread scheduler based o

Write Your Message!

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd