Java generates random integer Summary

Source: Internet
Author: User

Java generates random integers in different methods. For details, refer to the following code:

 

Import Java. security. securerandom; <br/> Import Java. util. random; <br/>/** <br/> * aiguoxin 2010-10-20 01:35:13 <br/> * Summary of Random Number Generation <br/> */<br/> Public class Radom {<br/> Public static void main (string [] ARGs) {<br/> // math. random () method <br/> for (INT I = 0; I <10; I ++) {<br/> system. out. print (INT) (math. random () * 100) + ""); <br/>} system. out. println ("/N" + "---------------------------"); <br/> // random numbers are different each time without seeds. <br/> random Rand = new random (); <br/> for (INT I = 0; I <10; I ++) {<br/> system. out. print (Rand. nextint (100) + ""); <br/>}< br/> system. out. println ("/N" + "---------------------------"); <br/> // with seeds, the random number is the same each time <br/> random rand2 = new random (10 ); <br/> for (INT I = 0; I <10; I ++) {<br/> system. out. print (rand2.nextint (100) + ""); <br/>}< br/> system. out. println ("/N" + "---------------------------"); <br/> // generate a random number that is completely unique <br/> securerandom random = new securerandom (); <br/> for (INT I = 0; I <10; I ++) {<br/> system. out. print (random. nextint (100) + ""); <br/>}< br/>}

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.