or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-7/

Random Value Picker

Build a utility that generates random values within specified ranges and selects random items from collections.

Capabilities

Generate random integers in range

  • Calling getRandomInt(1, 10) returns an integer between 1 and 10 inclusive @test
  • Calling getRandomInt(5, 5) always returns 5 @test
  • Calling getRandomInt(10, 1) correctly handles reversed bounds and returns an integer between 1 and 10 @test

Generate random floats in range

  • Calling getRandomFloat(0, 1) returns a float between 0 and 1 inclusive @test
  • Calling getRandomFloat(5.5, 10.5) returns a float between 5.5 and 10.5 @test

Select random items from array

  • Calling pickRandomItem(['apple', 'banana', 'cherry']) returns one of the three items @test
  • Calling pickRandomItem([42]) returns 42 @test

Implementation

@generates

API

/**
 * Generates a random integer between min and max (inclusive).
 * If only one argument is provided, returns a random integer between 0 and that number.
 * Handles reversed bounds automatically.
 *
 * @param {number} min - The lower bound (or upper bound if max is not provided)
 * @param {number} max - The upper bound (optional)
 * @returns {number} A random integer in the specified range
 */
function getRandomInt(min, max);

/**
 * Generates a random floating point number between min and max (inclusive).
 *
 * @param {number} min - The lower bound
 * @param {number} max - The upper bound
 * @returns {number} A random float in the specified range
 */
function getRandomFloat(min, max);

/**
 * Selects a random item from the provided array.
 *
 * @param {Array} items - The array to select from
 * @returns {*} A randomly selected item from the array
 */
function pickRandomItem(items);

module.exports = {
  getRandomInt,
  getRandomFloat,
  pickRandomItem
};

Dependencies { .dependencies }

lodash { .dependency }

Provides utility functions for working with numbers and arrays.

@satisfied-by