Java basics: Random and UUID

Source: Internet
Author: User
Package day7; import Java. util. random; import Java. util. UUID;/*** Java. util. random class * Java. util. UUID class */public class randomdemo {public static void main (string [] ARGs) {/** exercise: generate a pseudo-random number between [0,100) ** construction method: random () creates a new random number generator. * Int nextint () returns the next pseudo-random number, which is the int value uniformly distributed in the sequence of the random number generator * int nextint (int n) returns a pseudo-random number, it is an int value that is evenly distributed between 0 (inclusive) and specified value n (excluded) from the sequence of the random number generator. */random r = new random (); system. out. println (R. nextint (100);/** UUID class: class with a unique identifier (UUID. UUID indicates a 128-bit value. * It can be used as the primary key of the database * Static UUID randomuuid () to obtain the static factory of type 4 (pseudo-randomly generated) UUID. */UUID = UUID. randomuuid (); string u = UUID. tostring (); system. Out. println (U); // 26ce0eec-be3d-rjc-a2f5-f71c9466836d each time }}

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.