Github user xubo245 commented on a diff in the pull request: https://github.com/apache/spark/pull/14422#discussion_r72890434 --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Matrices.scala --- @@ -497,6 +497,20 @@ object DenseMatrix { } /** + * Generate a `DenseMatrix` consisting of `i.i.d.` uniform random numbers. + * + * @param numRows number of rows of the matrix + * @param numCols number of columns of the matrix + * @return DenseMatrix` with size `numRows` x `numCols` and values in U(0, 1) + */ + @Since("2.0.0") + def rand(numRows: Int, numCols: Int): DenseMatrix = { + require(numRows.toLong * numCols <= Int.MaxValue, + s"$numRows x $numCols dense matrix is too large to allocate") + new DenseMatrix(numRows, numCols, Array.fill(numRows * numCols)((new Random).nextDouble())) --- End diff -- Can fix RNG, This makes a new RNG for all element : val rng = new Random() new DenseMatrix(numRows, numCols, Array.fill(numRows * numCols)(rng.nextDouble()))
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org