版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1 год назад
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.randomElem = exports.randomBool = exports.randomRange = exports.randomInt = exports.random = void 0;
  4. /**
  5. * @since 2.0.0
  6. */
  7. var IO_1 = require("./IO");
  8. var function_1 = require("./function");
  9. /**
  10. * Returns a random number between 0 (inclusive) and 1 (exclusive). This is a direct wrapper around JavaScript's
  11. * `Math.random()`.
  12. *
  13. * @since 2.0.0
  14. */
  15. var random = function () { return Math.random(); };
  16. exports.random = random;
  17. /**
  18. * Takes a range specified by `low` (the first argument) and `high` (the second), and returns a random integer uniformly
  19. * distributed in the closed interval `[low, high]`. It is unspecified what happens if `low > high`, or if either of
  20. * `low` or `high` is not an integer.
  21. *
  22. * @since 2.0.0
  23. */
  24. function randomInt(low, high) {
  25. return (0, function_1.pipe)(exports.random, (0, IO_1.map)(function (n) { return Math.floor((high - low + 1) * n + low); }));
  26. }
  27. exports.randomInt = randomInt;
  28. /**
  29. * Returns a random number between a minimum value (inclusive) and a maximum value (exclusive). It is unspecified what
  30. * happens if `maximum < minimum`.
  31. *
  32. * @since 2.0.0
  33. */
  34. function randomRange(min, max) {
  35. return (0, function_1.pipe)(exports.random, (0, IO_1.map)(function (n) { return (max - min) * n + min; }));
  36. }
  37. exports.randomRange = randomRange;
  38. /**
  39. * Returns a random boolean value with an equal chance of being `true` or `false`
  40. *
  41. * @since 2.0.0
  42. */
  43. exports.randomBool = (0, function_1.pipe)(exports.random, (0, IO_1.map)(function (n) { return n < 0.5; }));
  44. /**
  45. * Returns a random element of a `ReadonlyNonEmptyArray`.
  46. *
  47. * @since 2.10.0
  48. */
  49. var randomElem = function (as) {
  50. return (0, function_1.pipe)(randomInt(0, as.length - 1), (0, IO_1.map)(function (i) { return as[i]; }));
  51. };
  52. exports.randomElem = randomElem;