Skip to main content

Randomizing Assessments

Rarely is everything in an assessment the same across repeated administrations or trials. Experiments often need variations in the stimuli, the order of the stimuli, or the timing of the stimuli. m2c2kit has helper randomization methods for common randomization tasks. These methods are available in the RandomDraws class.

A single random integer

For a single random integer, use the RandomDraws.SingleFromRange() method. This method takes minimumInclusive and maximumInclusive arguments, and returns a random integer between those two values, inclusive.

This code returns a random integer between 1 and 10, inclusive:

const randomInteger = RandomDraws.SingleFromRange(1, 10);

Multiple random integers

For multiple random integers, use the RandomDraws.FromRangeWithoutReplacement() method. This method takes n, minimumInclusive, and maximumInclusive arguments. It returns an array of n integers between those two values, inclusive. The integers are unique, meaning that no integer is repeated in the array.

This code returns an array of 4 integers between 1 and 24, inclusive:

const randomIntegers = RandomDraws.FromRangeWithoutReplacement(4, 1, 24);

Random words and colors

Below, we randomly choose two unique words from a word bank of 8 possible words. We then randomly assign the same color to both words from a bank of 4 colors.

Arrays in JavaScript are 0-based. For example, to choose 2 words from a word bank of 8 words, we need to choose 2 integers between 0 and 7, inclusive. These two random integers are then used to index into the word bank array.

Click the "Run" button multiple times to see how the words and colors change.

Loading...