Maptitude GISDK Help

RandSamples()

Summary

Return an array of random samples of the given type of random distribution and parameters defined in the options array.

 

Changes

Added to Version 2019.

 

Syntax

sample_vector = RandSamples(int n, string type, opt array params)

 

Argument

Contents

n

The number of samples to return (in an array)

type

One of the following strings:

 

Type

Description

Uniform

Random numbers between 0.0 (inclusive) and 1.0 (exclusive) with uniform distribution. If option "population" is provided, then  the return values will be items in the array rather than values between 0.0 and 1.0.

Discrete

Random numbers between 1 and n based on the probability densities defined by option "weight", where n is the length of the "weight" array. An option "population", which has the same length as "weight", can also be given if you want the return values to be drawn from the population array instead of the 1-based index to the population bins. Items in the population array can be int, string, double, or color.

Binary

Random numbers of 1 and 0, with probability of 1 given by optional parameter "p" (default is 0.5).

NegativeExp

Random numbers of negative exponential distribution. Requires parameter "lambda"

Poisson

Random integers from the Poisson distribution. Requires parameter "lambda".

Norm

Random numbers of Normal distribution. Optional parameters are mean "mu" (0.0) and standard derivation "sigma" (1.0).

LogNorm

Random numbers of Log Normal distribution. Optional parameters are mean "mu" (0.0) and standard derivation "sigma" (1.0).

Gumbel

 Random numbers of Gumbal distribution. Optional parameters are mode "mu" and standard derivation "sigma".

Gamma

Random numbers of Gamma distribution. Parameters are "shape" (k) and "scale" (theta).

 

The options supported vary by distribution type:

 

Uniform:

Option

Type

Contents

population

array or vector

If provided, returned values will be drawn from this array or vector. If not provided, returns a value between 0 and 1.

 

Discrete:

Option

Type

Contents

population

array or vector

If provided, returned values will be drawn from this array or vector. If not provided, returns an integer between 1 and the length of the Weight array or vector.

weight

array or vector

Defines the weights to use for sampling. Defaults to an array or vector of size n filled with the value 1.

 

Binary:

Option

Type

Contents

p

real or array

A value between 0 and 1.0 that describes the probability of sampling a 1. Defaults to 0.5.

 

NegativeExp and Poisson:

Option

Type

Contents

lambda

real or array

Describes the shape of the distribution. Must be greater than 0. Defaults to 1.

 

Norm, LogNorm, and Gumbell:

Option

Type

Contents

mu

real or array

The mean of the distribution for "Norm" and "LogNorm". For "Gumbell", it is the mode. Defaults to 0.

sigma

real or array

The standard deviation of the distribution. Defaults to 1.

 

Gamma:

Option

Type

Contents

shape

real or array

Controls the shape of the function. Defaults to 1.

scale

real or array

Controls the scale of the function. Defaults to 1.

 

Returns

A vector of random samples.

 

Notes

 

Examples

// Example 1

SetRandomSeed(42)

params = null

params.population = { "A", "B", "C", "D", "E" }

samples = RandSamples(10, "Uniform", params)

// samples = { "vector", { "A", "B", "A", "A", "A", "C", "C", "A", "A", "D" } }

 

// Example 2

SetRandomSeed(42)

params = null

params.population = { "A", "B", "C", "D", "E" }

params.weight = { 20, 45, 18, 4, 22 }

samples = RandSamples(10, "Discrete", params)

// samples = { "vector", { "A", "B", "A", "A", "A", "B", "B", "B", "A", "C" } }

 

// Example 3

SetRandomSeed(42)

params = null

params.mu = 1

params.sigma = 2

samples = RandSamples(5, "Norm", params)

// samples = { "vector", { -0.487258, -0.486241, -4.497264, -1.318424, -1.180147 } }

 

// Example 4

SetRandomSeed(1)

params = null

params.p = .75

samples = RandSamples(10, "Binary", params)

// samples = { "vector", { 1, 1, 0, 1, 1, 1, 1, 0, 0, 1 } }

 

// Example 5 - using vectors/arrays for parameters

SetRandomSeed(42)

params = null

params.mu = {1.2, 4.6, 17.2}

// Vectors work, too:

// params.mu = A2V({1.2, 4.6, 17.2})

samples = RandSamples(3, "Norm", params)

// samples = { "vector", { 0.456371, 3.856879, 14.451368 } }

 

See Also

Function

Summary

SetRandomSeed()

Seeds the RandomNumber() function

 

 

©2025 Caliper Corporation www.caliper.com