I'm creating a Neural Network in Java and need to create a method to generate random weights initially.
I need to create a function that returns a random double value between -1 and 1 but not sure of the logic for doing this so any help would be most appreciated.
You can use the Random class's nextDouble() method.
Random rng = new Random();
// to get a double between -1 and 1
return rng.nextDouble() * 2 - 1; // rng.nextDouble() is between 0 and 1
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