Java-random class

Source: Internet
Author: User

Package Com.day10.Random class;

Import Java.util.Random;

public class Demorandom {

/**
* @param args
* Common Objects (Overview of the Random class and methods used)
* Overview of the A:random class
* This class is used to generate random numbers if you create two random instances with the same seed,
* The same method call sequence is made for each instance, and they will generate and return the same sequence of numbers.
* B: Construction method
* Public Random ()
* Public Random (long Seed)
* C: Member method
* public int Nextint ()
* public int Nextint (int n) (Key Mastery)
*/
public static void Main (string[] args) {
Random r=new random ();
int X=r.nextint ();
SYSTEM.OUT.PRINTLN (x);//The number randomly generated within the value range of int
Request to Master
System.out.println (R.nextint (100));//number of randomly generated [0,100]

Random r1=new Random (1000);
int A=r1.nextint ();
int B=r1.nextint ();
System.out.println (a);//-1244746321 this number every time, because it's the same seed.
System.out.println (b);//1060493871 This number every time, because it's the same seed.

}

}

Java-random class

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.