In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the random number generation methods in java, which have a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
The generation of random numbers is very common in some code, and we must master it. There are three main ways to generate random numbers in java:
The first kind: new Random ()
The second kind: Math.random ()
The third kind: currentTimeMillis ()
The first requires the help of the java.util.Random class to generate a random number generator, which is also the most commonly used. There are two constructors, Random () and Random (long seed). The first is to use the current time as the default seed, and the second is to use the specified seed value. After generation, different types of numbers are generated with the help of different statements.
The seed is to generate the first use value of the random number, the mechanism is that through a function, the value of the seed is transformed into a certain point in the random number space, and the resulting random number is evenly distributed in the space. The random number generated later is related to the previous random number. Take the code as an example.
Public static void main (String [] args) {Random r = new Random (1); for (int iTun0; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.