Java.util.Random in-depth understanding

Source: Internet
Author: User

Java.util.RandomThe principle of Next method

Better reference Documentation:

http://isky001.iteye.com/blog/1339979

 PackageRandom.utilrandom;ImportJava.util.Random; Public classTestrandom { Public Static voidMain (string[] args) {Random ran1=NewRandom (10); System.out.println ("Generates a sequence of random integers in [0,10] using a random object with seed 10:");  for(inti = 0; I < 10; i++) {System.out.print (Ran1.nextint (10) + "");        } System.out.println (); Random ran2=NewRandom (10); System.out.println ("Generates a sequence of random integers in [0,10] using another random object with a seed of 10:");  for(inti = 0; I < 10; i++) {System.out.print (Ran2.nextint (10) + ""); } Random ran3=NewRandom (10); System.out.println ("Generates a sequence of random integers in [0,10] using another random object with a seed of 10:");  for(inti = 0; I < 10; i++) {System.out.println (Ran3.nextint ());        } System.out.println (); Random Ran4=NewRandom (10); System.out.println ("Generates a sequence of random integers in [0,10] using another random object with a seed of 10:");  for(inti = 0; I < 10; i++) {System.out.println (Ran4.nextint ()); }    }}

Math.random () is essentially called RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble (); That is java.util.Random.nextDouble ()

There is also an article that explains the linear congruence formula.

Http://www.cnblogs.com/xkfz007/archive/2012/03/27/2420154.html

One more english document explanation Nextseed = (Oldseed * multiplier + addend) & mask;

Http://en.wikipedia.org/wiki/Linear_congruential_generator

Java.util.Random in-depth understanding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.