Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Hands on the RandomDataGenerator class in Apache Commons Math

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

%classpath add mvn org.apache.commons commons-math3 3.6.1
Loading...
Loading...
import org.apache.commons.math3.random.RandomDataGenerator
import collection.JavaConverters._
val rng = new RandomDataGenerator()
scala.collection.JavaConverters$@783d0556

Notice that the both of the endpoints are included, which is different from typcial Java conventions!!!

rng.nextInt(0, 2)
2
rng.nextInt(0, 1)
1
rng.nextInt(0, 1)
0
rng.nextPermutation(5, 3)
[4, 3, 0]
rng.nextPermutation(5, 3)
[2, 3, 0]
val vec = Vector(10, 20, 30, 40, 50)
[[10, 20, 30, 40, 50]]
rng.nextSample(vec.asJava, 3).mkString(" ")
50 20 10
rng.nextSample(vec.asJava, 3).mkString(" ")
50 30 40