With your current solution you'd need to iterate with a counter starting from 0 and ending before the given size, assigning each array element with a nextDouble
invocation.
Multiplying an array object by a number is just not supported in Java.
Here's a Java-8 idiom that you may favor instead:
DoubleStream
.generate(ThreadLocalRandom.current()::nextDouble)
.limit(yourGivenSize)
.toArray();
This will give you a double[]
of size yourGivenSize
, whose elements are generated randomly.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…