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;
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]);


Related Discussions:- Explain java.util.random package

Retrieving file records randomly, how to retrieve multiple records randomly...

how to retrieve multiple records randomly from a file and store it in another file

Explain the essential api concepts associated with j2me, Question : (a)...

Question : (a) Class file verification in CLDC is different from class file verification in J2SE. Explain and discuss how and why it is different, illustrating your answer

For statement in javascript, A for loop repeats until a specified condition...

A for loop repeats until a specified condition evaluates to false. For for loop the JavaScript is similar to the Java and C for loops. A for statement looks as:  for ([initial-

Develop a 3d rolling alarm clock, Need to develop a 3D rolling alarm clock ...

Need to develop a 3D rolling alarm clock (Android) Project Description: I want an android app as 3D rolling alarm clock It should have sound effect when setting the alarm

Differentiation between an applet and an application, Differentiation betwe...

Differentiation between an Applet and an Application ?

Create an android application., We need to create an Android application. T...

We need to create an Android application. The application is about registering courses in a university, viewing grades, available courses and evaluating faculty members. Advisor

What are the different types of bean injections, Two types of bean injectio...

Two types of bean injections are there:- 1. By setter 2. By constructor

Write a recursive function, 1) Write a function that uses recursion that co...

1) Write a function that uses recursion that converts a decimal number to octal (base 8). The function should accept a single integer and return a String containing the base 8 equi

Write javascript code to scans the list of courses , In an external JavaScr...

In an external JavaScript file write code that, upon form submission, scans the list of courses for a match (case should be insensitive). If a match is found, change the div's back

What do you understand by private and public class, What do you understand ...

What do you understand by private, protected and public? These are accessibility modifiers. Private is the most restrictive, whereas public is the least restrictive. There is n

Write Your Message!

Captcha
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