This is an automated email from the ASF dual-hosted git repository. aherbert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-rng.git
commit 4e7a4c80bf76d0388059600f8f22f06a3a3ace9a Author: aherbert <[email protected]> AuthorDate: Wed May 4 15:09:34 2022 +0100 RNG-177: Add streaming examples to the user guide --- src/site/apt/userguide/rng.apt | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/site/apt/userguide/rng.apt b/src/site/apt/userguide/rng.apt index 3b080726..950868ec 100644 --- a/src/site/apt/userguide/rng.apt +++ b/src/site/apt/userguide/rng.apt @@ -378,6 +378,34 @@ DiscreteSampler sampler = RejectionInversionZipfSampler.of(RandomSource.ISAAC.cr int random = sampler.sample(); +--------------------------+ + * Sampler interfaces are provided for generation of the primitive types <<<int>>>, <<<long>>>, and <<<double>>> + and objects of type <<<T>>>. The <<<samples>>> method creates a stream of sample values + using the Java 8 streaming API: + ++--------------------------+ +import org.apache.commons.rng.sampling.distribution.PoissonSampler; +import org.apache.commons.rng.simple.RandomSource; + +double mean = 15.5; +int streamSize = 100; +int[] counts = PoissonSampler.of(RandomSource.L64_X128_MIX.create(), mean) + .samples(streamSize) + .toArray(); ++--------------------------+ + ++--------------------------+ +import org.apache.commons.rng.sampling.distribution.ZigguratSampler; +import org.apache.commons.rng.simple.RandomSource; + +// Lower-truncated Normal distribution samples +double low = -1.23; +double[] samples = ZigguratSampler.NormalizedGaussian.of(RandomSource.L64_X128_MIX.create()) + .samples() + .filter(x -> x > low) + .limit(100) + .toArray(); ++--------------------------+ + * The <<<SharedStateSampler>>> interface allows creation of a copy of the sampler using a new generator. The samplers share only their immutable state and can be used in parallel computations. @@ -468,10 +496,11 @@ ListSampler.shuffle(rng, list) import org.apache.commons.rng.sampling.shape.BoxSampler; double[] lower = {1, 2, 3}; -double[] upper = {15, 16, 17} +double[] upper = {15, 16, 17}; BoxSampler sampler = BoxSampler.of(RandomSource.KISS.create(), lower, upper); double[] coordinate = sampler.sample(); +double[][] coordinates = sampler.samples(100).toArray(double[][]::new); +--------------------------+ * The
