Languages
[Edit]
EN

Java - Math.random() method example

0 points
Created by:
daniell
490

The Math.random() function returns floating-point, pseudo-random number between range [0,1), 0 (inclusive) and 1 (exclusive). Based on this function we are able to get a random number in range as we can see in the below examples.

Simple usage example:


1. Documentation

Edit
Syntax

Note: Classes in the java.lang package are imported automatically, so it is not necessary to do it manually - we use just Math.random() call.

ParametersThis method does not take any arguments.
Resultdouble number value (primitive value).
Descriptionrandom is a static method that returns random float number from the
range <0, 1) - inclusive 0 and exclusive 1.

2. Custom random method examples

Edit

2.1. Random double in range example

Edit

This example shows how to random numbers.

2.2 With nextDouble() method

Edit

References

Edit
  1. Random number generation - Wikipedia
  2. Pseudorandom number generator - Wikipedia
  3. List of random number generators - Wikipedia
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - Math object

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join