Random numbers in Java (Math.random ()), and how to produce a random number similar to the [21,77] interval.

Source: Internet
Author: User
Math.random () produced by [0,1]!!! Double K=math.random ();//Note the following = to be added, so as to satisfy the mathematical symmetry if (k>=0.5)// This means that when the random number produced is greater than or equal to 0.5, say that own cow B, less than 0.5 said this own silly BSystem.out.println ("I live between cattle a and cattle C" +k); ElseSystem.out.println ("I live between silly a and silly C" +k) //===========================================================int a=13;int b=25;//premise is B>A!!! The method to produce an integer between [a, b] is (Math.random () * (b-a+1) +a)) int r = (int) (Math.random () * (b-a+1)) +a; System.out.println (R);//===========================================================//outputs the characters between 65--90 [A,z]for (int i = 0; I < 26; i++) {int c = (int) (Math.random () * (90-65+1) +65);//or * (z-a+1) +asystem.out.println ((char) c);//convert to corresponding ASCII character}

Random numbers in Java (Math.random ()), and how to produce a random number similar to the [21,77] interval.

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.