ReferencesampleRandomNumbers

<sampleRandomNumbers/>

Samples random numbers from a distribution

<sampleRandomNumbers/> is a Math component that generates random numbers from a specified range of values or within a normal distribution around a specified mean. It differs from the <selectRandomNumbers/> component in that the values can be altered within the document by resampling or changing one or more of the component’s attributes. The primary application of the <sampleRandomNumbers/> component is for use in simulations involving random numbers.

Attributes and Properties

Attributes for <sampleRandomNumbers>

Other (16)
asList

boolean. Default value: true. Whether to render the items separated by commas (true) or with no separator (false).

avoidScientificNotation

Whether to render numbers in full decimal form rather than scientific notation.

displayDecimals

Number of decimal places to display when rendering this number.

displayDigits

Number of significant digits to display when rendering this number.

displaySmallAsZero

Threshold below which numbers are displayed as zero.

numberList. Values to exclude from the sample space.

number. Lower bound of the sampling range.

mean

number. Default value: 0. Mean of the sampling distribution (Gaussian).

number. Default value: 1. Number of samples to draw.

padZeros

Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

standardDeviation

number. Default value: 1. Standard deviation of the sampling distribution (Gaussian).

number. Default value: 1. Step size between samples for the discrete-uniform distribution.

number. Upper bound of the sampling range.

type

keyword. Distribution from which to sample.

ValueDescription
uniform (default)Continuous uniform distribution over [from, to].
discreteUniformDiscrete uniform distribution over integers in [from, to].
gaussianNormal (Gaussian) distribution with the specified mean and standard deviation.
variance

number. Default value: 1. Variance of the sampling distribution (Gaussian).

variantDeterminesSeed

boolean. Whether the document's variant index determines the random seed.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <sampleRandomNumbers name="s">

Other (9)
$s.from

number. Lower bound of the sampling range.

$s.mean

number. Mean of the sampling distribution.

$s.numSamples

number. Number of samples to draw.

$s.standardDeviation

number. Standard deviation of the sampling distribution.

$s.step

number. Step size between sample values (for discrete distributions).

$s.to

number. Upper bound of the sampling range.

$s.type

text. Distribution from which to sample.

$s.variance

number. Variance of the sampling distribution.

$s.variantDeterminesSeed

boolean. Whether the document's variant index determines the random seed.

Common to all components (4)
$s.doenetML

text. The DoenetML source code that produced this component.

$s.hide

boolean. Whether to hide this component from the rendered output.

$s.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$s.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: Default <sampleRandomNumbers/>

Without any attributes specified, the default sampling type is uniform, and the default interval is [0,1)[0, 1). In this example, there are two ways to view different samples: selecting another variant, or refreshing the page.


Example: Using a re-sampling button

Without any attributes specified, the default sampling type is uniform, and the default interval is [0,1)[0, 1). The <callAction> button can be used to resample the value.

Attribute Examples

Attribute Example: numSamples

The <sampleRandomNumbers/> component is used with the numSamples attribute to select multiple random values in the default interval [0,1)[0,1). The default type is uniform.


Attribute Example: from, to

The <sampleRandomNumbers/> component is used with the from and the to attributes to modify the default selection interval. The default type is uniform.


Attribute Example: type = “discreteUniform”

The type attribute of the <sampleRandomNumbers/> component is specified as discreteUniform. The discreteUniform selection generates values from an evenly spaced range defined by the attributes to, from, and step. If left unspecified, the default step is 1.


Attribute Example: exclude

The type attribute of the <sampleRandomNumbers/> component is specified as discreteUniform. Values can be excluded from the specified range used with this type using the exclude attribute.


Attribute Example: step

The type attribute of the <sampleRandomNumbers/> component is specified as discreteUniform. The discreteUniform selection generates values from an evenly spaced range defined by the attributes to, from, and step. If left unspecified, the default step is 1.


Attribute Example: type = “gaussian”

The type attribute of the <sampleRandomNumbers/> component is specified as gaussian. The gaussian selection generates standard normal variables (mean 0, variance 1). Alternatively, the mean as well as the variance or the standardDeviation attributes may be defined.


Attribute Example: gaussian with mean and variance

The type attribute of the <sampleRandomNumbers/> component is specified as gaussian. The gaussian selection generates standard normal variables (mean 0, variance 1). In this example, the mean and the variance are defined with attributes.


Attribute Example: gaussian with mean and standardDeviation

The type attribute of the <sampleRandomNumbers/> component is specified as gaussian. The gaussian selection generates standard normal variables (mean 0, variance 1). In this example, the mean and the standardDeviation are defined with attributes.