🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Random.html
Random (Java Platform SE 8 )
2 weeks ago - Java™ Platform Standard Ed. 8 ... An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1.) If two instances ...
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › Random.html
Random (Java SE 21 & JDK 21)
January 20, 2026 - If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers. In order to guarantee this property, particular algorithms are specified for the class Random. Java implementations must use all the algorithms shown here for the class Random, for the sake of absolute portability of Java code.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.random
Random Class (Java.Util) | Microsoft Learn
If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers. In order to guarantee this property, particular algorithms are specified for the class Random. Java implementations must use all the algorithms shown here for the class Random, for the sake of absolute portability of Java code.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-util-random-class-java
Java.util.Random class in Java - GeeksforGeeks
July 23, 2025 - Random class is used to generate pseudo-random numbers in java. An instance of this class is thread-safe. The instance of this class is however cryptographically insecure. This class provides various method calls to generate different random ...
🌐
Java
download.java.net › java › early_access › panama › docs › api › java.base › java › util › random › package-summary.html
java.util.random (Java SE 19 & JDK 19 [build 1])
The principal interface is RandomGenerator, which provides methods for requesting individual values of type int, long, float, double, or boolean chosen pseudorandomly from a uniform distribution; methods for requesting values of type double chosen pseudorandomly from a normal distribution or from an exponential distribution; and methods for creating streams of values of type int, long, or double chosen pseudorandomly from a uniform distribution (such streams are spliterator-based, allowing for parallel processing of their elements).
🌐
Baeldung
baeldung.com › home › java › java numbers › generating random numbers in java
Generating Random Numbers in Java | Baeldung
January 8, 2024 - In this tutorial, we’ll explore different ways of generating random numbers in Java. The Java API provides us with several ways to achieve our purpose.
🌐
Android Developers
developer.android.com › api reference › random
Random | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Find elsewhere
🌐
Meinzeit
meinzeit.com › webTeach › courses › APCS-A › resources › Java Notes 2007 › algorithms › random › random-api.html
Java: Random numbers - API
Two classes. Java provides the Math.random() method as well as the java.util.Random class. The methods of the Random class often produce random numbers in a more convenient form, but requires creating an object, which sometimes is inconvenient. In constrast, the Math.random() method produces a double value which must sometimes be translated and cast into the form you need it.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-random
Java Random | DigitalOcean
August 4, 2022 - We can see that it will generate same random number if we pass same seed to two different random number generators. As you can see from above image, there are many new methods added in Java 8 to Random class. These methods can produce a stream of random numbers.
🌐
W3Schools
w3schools.com › java › java_howto_random_number.asp
Java How To Generate Random Numbers
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... You can use Math.random() method to generate a random number.
🌐
Baeldung
baeldung.com › home › java › java numbers › random number generators in java
Random Number Generators in Java | Baeldung
January 8, 2024 - The original API consists of four classes with no interfaces: The most commonly used random number generator is Random from the java.util package.
🌐
Quora
quora.com › What-is-the-use-of-math-random-in-Java
What is the use of math.random() in Java? - Quora
Answer (1 of 6): The java.lang.Math.random() returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › random
Math.random() - JavaScript | MDN
Use the Web Crypto API instead, and more precisely the Crypto.getRandomValues() method. function getRandomInt(max) { return Math.floor(Math.random() * max); } console.log(getRandomInt(3)); // Expected output: 0, 1 or 2 console.log(getRandomInt(1)); // Expected output: 0 console.log(Math.random()); // Expected output: a number from 0 to <1 ... A floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). Note that as numbers in JavaScript are IEEE 754 floating point numbers with round-to-nearest-even behavior, the ranges claimed for the functions below (excluding the one for Math.random() itself) aren't exact.
Top answer
1 of 13
29

Check out http://random.org/

RANDOM.ORG is a true random number service that generates randomness via atmospheric noise.

The Java library for interfacing with it can be found here: http://sourceforge.net/projects/trng-random-org/

2 of 13
25

Your question is ambiguous, which is causing the answers to be all over the place.

If you are looking for a Random implementation which relies on the system's source of randomness (as I'm guessing you are), then java.security.SecureRandom does that. The default configuration for the Sun security provider in your java.security file has the following:

#
# Select the source of seed data for SecureRandom. By default an
# attempt is made to use the entropy gathering device specified by
# the securerandom.source property. If an exception occurs when
# accessing the URL then the traditional system/thread activity
# algorithm is used.
#
# On Solaris and Linux systems, if file:/dev/urandom is specified and it
# exists, a special SecureRandom implementation is activated by default.
# This "NativePRNG" reads random bytes directly from /dev/urandom.
#
# On Windows systems, the URLs file:/dev/random and file:/dev/urandom
# enables use of the Microsoft CryptoAPI seed functionality.
#
securerandom.source=file:/dev/urandom

If you are really asking about overriding this with something even more truly random, it can be done either by changing this property, or by using another SecureRandom. For example, you could use a JCE provider backed by an HSM module such as nCipher nShield which has its own PRNG, or other solutions mentioned in the thread.

🌐
GitHub
github.com › j-easy › easy-random
GitHub - j-easy/easy-random: The simple, stupid random Java beans/records generator · GitHub
Easy Random is a library that generates random Java objects. You can think of it as an ObjectMother for the JVM.
Starred by 1.7K users
Forked by 236 users
Languages   Java
🌐
Baeldung
baeldung.com › home › java › java numbers › generating random numbers in a range in java
Generating Random Numbers in a Range in Java | Baeldung
May 11, 2024 - Generate Bounded and Unbounded Random Strings using plain Java and the Apache Commons Lang library.