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!
Note: Math.random() does not provide cryptographically secure random numbers. Do not use them for anything related to security. Use the Web Crypto API instead, and more precisely the window.crypto.getRandomValues() method.
If you don't like the Math.Random you can make your own Random object.
import:
import java.util.Random;
code:
Random rand = new Random();
int value = rand.nextInt();
If you need other types instead of int, Random will provide methods for boolean, double, float, long, byte.
In JavaScript using the Middle-square method.
var _seed = 1234;
function middleSquare(seed){
_seed = (seed)?seed:_seed;
var sq = (_seed * _seed) + '';
_seed = parseInt(sq.substring(0,4));
return parseFloat('0.' + _seed);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With