My project entails that I create a basic number guessing game that uses the JOptionPane and does not use Math.Random to create the random value. How would you go about doing this? I've completed everything except the random number generator. Thanks!
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Here the code for a Simple random generator:
The code above is a "Linear congruential generator (LCG)", you can find a good description of how it works here.
Disclamer:
In JavaScript using the Middle-square method.
You could use java.security.SecureRandom. It has better entropy.
Also, here is code from the book Data Structures and Algorithm Analysis in Java. It uses the same algorithm as java.util.Random.
If you don't like the Math.Random you can make your own Random object.
import:
code:
If you need other types instead of int, Random will provide methods for boolean, double, float, long, byte.