Java java.uitl.Random generates random numbers

Source: Internet
Author: User

Generates a random number within 1-10 by using Java.uitl.Random. Cases:

1 New Random (); 2 int i = Math.Abs (Random.nextint ()%) + 1; 3 System.out.println ("Random number:" + i);

Random uses System.currenttimemillis () as the default seed, and of course you can create a seed yourself when you construct the random, just at this point in time of the run (for random objects of the same seed), The resulting random number is the same, so the default neutron is used here, and the Nextint () method is called to modulo 10, get 0-9 of the random number, and then +1, to produce a random number effect of 1-10.

Java java.uitl.Random generates random numbers

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.