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

I want java web developer finish a webcam site, Java Web Developer A web...

Java Web Developer A web developer is required to finish a webcam site with basic account management and voting functionality. The website can make use of a third party flash

Describe even higer dimensions in java, Describe even higer dimensions in j...

Describe even higer dimensions in java? You don't have to stop along with two dimensional arrays. Java allows arrays of three, four or more dimensions. Therefore chances are pr

Dropbox calendar, code in dropbox calendar and loop for feruary leapyear

code in dropbox calendar and loop for feruary leapyear

How marketing strategies are changed along with the progress, How marketing...

How marketing strategies are changed along with the progress in computing? How latest marketing strategies are implemented? Marketing Strategy Changes along with the latest req

Program that can communicate with a smtp email server, Assignment Your t...

Assignment Your task in this assignment is to develop a Java program that can communicate with a real SMTP email server for sending emails. It should have a graphical user inter

Garbage collection model, This assignment is about experimenting with the J...

This assignment is about experimenting with the Java runtime system's garbage collection model, and comparing it with the C++ manual memory allocation model. Below is the Garbage J

Payroll calculator application, Payroll Calculator for Both Hourly and Comm...

Payroll Calculator for Both Hourly and Commission Employees In assignment 13, we will create a payroll calculator that calculates   gross pay ,   taxes , and   net pay   fo

Difference between static and non-static variable, What is the difference b...

What is the difference between static and non-static variables? A static variable is associated with the class as a whole rather than with specific instances of a class. Non-st

Enumerate the concept of write once run anywhere - java, Enumerate the conc...

Enumerate the concept of write once run anywhere - JAVA Java has introduced concept of WORA (write once run anywhere). When you write a java program it is called source code of

Using polymorphism to write a program to display digital clo, using polymor...

using polymorphism to write a program to display digital clock

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