Skip to content

Commit

Permalink
RNG-177: Add streaming examples to the user guide
Browse files Browse the repository at this point in the history
  • Loading branch information
aherbert committed May 4, 2022
1 parent dc779b4 commit 4e7a4c8
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/site/apt/userguide/rng.apt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4e7a4c8

Please sign in to comment.