The Radom class in Java

Source: Internet
Author: User

/* Generate random number */import java.util.random;public class randomtest01{public static void  Main (String[] args) {//Creates a new random number generator random r = new random ();//generates a random number of type int//int i  = r.nextint (101);  //[0-100] Random number//system.out.println (i);//loop generates 5 random numbers for (int i=0;i<5;i+ +) {System.out.println (R.nextint (101));} Generate five distinct random numbers [1-5]public class randomtest02{    public static void  main (STRING[]&NBSP;AGRS) {    //Create a random number generator object          random r=new random ();        int index=0;         int[] ari = new int[5];         int tmp=0;        while (index<5)          {      &nbsP;      tmp=r.nextint (6);              system.out.println ("-----------");              if (Tmp!=0 && !contain (ari,tmp) {                  system.out.println ("#############");                 ari[index++]  = tmp;             }          }    }    public static  int contain (int[] ari,int tmp)     {         for (int i=0;i<ari.length;i++) {             if (ari[i]==TMP) {                return  true;            }         }      return false;    }}


This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1662516

The Radom class in Java

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.