randomized/random Home Manual Reference Source

src/api/randrange.js

  1. import _randrange from '../kernel/_randrange.js';
  2. import randint from './randint.js';
  3.  
  4. /**
  5. * Pick an element from range(start, stop, step) uniformly at random.
  6. *
  7. * Return an element from range(start, stop, step) selected uniformly at random.
  8. * If step is positive, this set corresponds to
  9. * {x: x in [start, stop[ AND x % step = 0}.
  10. * If step is negative, the range has to be given in reverse order, that is,
  11. * largest value first, smallest value second. Both the starting value and the
  12. * step value are optional. By default the starting value is <code>0</code>.
  13. * The default for the step value is <code>1</code>.
  14. *
  15. * TODO: Handle empty ranges.
  16. *
  17. * @function
  18. * @param {number} [start=0] - The starting value.
  19. * @param {number} stop - The stopping value.
  20. * @param {number} [step=1] - The step value.
  21. * @return {number} The picked element.
  22. */
  23. const randrange = _randrange(randint);
  24. export default randrange;