[Java] Random method

A class provided in Java from the beginning, java.util.Random java.lang.Math There are these two.

This time, I will briefly explain the random method of Math class (java.lang.Math). Math.random() point -The return type is double ・ Get random numbers in the range of 0.0 to less than 1.0

Example ①double rand = Math.random(); ②double rand = Math.random() * 10; ③int rand = (int)(Math.random() * 10);

(1) Since the return type is double, a compile error will occur unless the variable type is basic double. (2) When acquiring a random number in the range of 0.0 to less than 10.0, add * 10 after the random method. (3) If you want to get a random number as an integer, you need to cast (2) to int type.

Recommended Posts

[Java] Random method
Java method
java (method)
Java method
[Java] method
[Java] method
[Java] Random number generation method (Random)
java (random number)
Java8 method reference
java8 method reference
[Java] split method
JAVA DB connection method
Java learning 2 (learning calculation method)
Java learning memo (method)
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Studying Java 8 (see method)
Java programming (class method)
Java random, various processing
[Java] Basic method notes
[Java] New Thread generation method (2)
Java GC method determination conditions
Create a java method [Memo] [java11]
Java test code method collection
[Java Silver] About equals method
Java
Java
Benefits of Java static method
[Java Silver] Array generation method
[Java] New Thread generation method (1)
[Java] Object-oriented syntax --class method / argument
Automatic photo resizing method in Java
Java method list (memorial) (under construction)
[Java] How to use join method
Screen transition by Post method [Java]
[Java] Object-oriented syntax-class / field / method / scope
Java comparison using the compareTo () method
[Java beginner] == operator and equals method
Try using IBM Java method tracing
[Java] Proxy setting method when starting Java
Java beginner design pattern (Factory Method pattern)
[Java] Processing time measurement method memo
Call the super method in Java
Implementation of clone method for Java Record
My thoughts on the equals method (Java)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
Java runtime environment construction method (Tomcat @ Linux)
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
java (constructor)
to_i method
Java array
[Java] ArrayDeque