Home > Java > javaTutorial > Share three java code tutorials for generating random numbers

Share three java code tutorials for generating random numbers

Y2J
Release: 2017-05-11 09:29:57
Original
1812 people have browsed it

This article mainly introduces the method of generating random numbers in Java, which has a good reference value. Let’s take a look at it with the editor

1. Use System.currentTimeMillis() to get a long number of milliseconds in the current time.

  long a = System.currentTimeMillis();
  System.out.println(a);
Copy after login

2. Return a double value between 0 and 1 through Math.random().

  int b = (int)(Math.random()*99+1);
  System.out.println(b);
Copy after login

3. Generate a random number through the Random class.

Random random = new Random();
  int c = random.nextInt(100)+1;
  System.out.println(c);
Copy after login

【Related recommendations】

1. Java Free Video Tutorial

2. Geek Academy Java Video Tutorial

3. Alibaba Java Development Manual

The above is the detailed content of Share three java code tutorials for generating random numbers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template