How does random.nextDouble() work?

public class InputDataGenerator {
//input data generator that will generate matrix values with a given size as parameter and a seed for the random generator
public Matrix matrixGenerator(int rows, int cols, int seed) {
Matrix matrix = new Matrix(rows, cols);
Random random = new Random(seed);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix.setSlow(i, j, random.nextDouble());
}
}
return matrix;
}
}
public class InputDataGenerator {
//input data generator that will generate matrix values with a given size as parameter and a seed for the random generator
public Matrix matrixGenerator(int rows, int cols, int seed) {
Matrix matrix = new Matrix(rows, cols);
Random random = new Random(seed);
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
matrix.setSlow(i, j, random.nextDouble());
}
}
return matrix;
}
}
I need to create a random data generator to create Matrices, and I was confused about how random.nextDouble() worked? It seems to only return values between 0.0 and 1.0? If I create 20 different matrices using the above method that has size 4096x4096 would it create enough random numbers?
3 Replies
JavaBot
JavaBot•3y ago
Hey, @Steadhaven! Please remember to /close this post once your question has been answered!
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot•3y ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.

Did you find this page helpful?