Let me also talk about the differences between Java: Random. nextint () and math. Random ().

Source: Internet
Author: User

Let me also talk about the differences between Java: Random. nextint () and math. Random ().
I don't care about efficiency. Today, when I quickly sorted data structures, I used random numbers to see this point. In fact, here we should say exactly
The difference between random. nextint (int n) and math. Random () * n is because the difference exists. Look at the documentation. Why are there so many other people?
The first is to comment on their efficiency, and they are fundamentally different. Because Random. nextint (int n) is from 0 to N, but n is not included, the problem arises here,
Math. Random () * n is probably very close to N. Most of them use integers. Why do we need to compare them like this?
So this should be called
What is the difference between random. nextint (N) and math. Random () * (n-1) or random. nextint (n + 1) and math. Random () * n,

Another important difference is that, in practical use, when used together with other applications, there will be great differences. I don't need to talk about it here.
Haha

Related Article

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.