File tree Expand file tree Collapse file tree 6 files changed +79
-5
lines changed Expand file tree Collapse file tree 6 files changed +79
-5
lines changed Original file line number Diff line number Diff line change 1+ import random from './random.js' ;
2+ import _randfloat from '../kernel/_randfloat.js' ;
3+
14/**
2- * Returns a floating point number in interval [i, j[ (i included, j excluded)
5+ * Returns a double in interval [i, j[ (i included, j excluded)
36 * according to a uniform distribution.
7+ *
8+ * @function
9+ * @param {number } i The inclusive left bound
10+ * @param {number } j The non-inclusive right bound
11+ * @return {number } A double in the interval [i, j[ taken uniformly at
12+ * random.
413 */
5-
6- const randfloat = ( i , j ) => i + Math . random ( ) * ( j - i ) ;
14+ const randfloat = _randfloat ( random ) ;
715export default randfloat ;
Original file line number Diff line number Diff line change 1+ import random from './random.js' ;
2+ import _randint from '../kernel/_randint.js' ;
3+
14/**
25 * Returns an integer in interval [i, j[ (i included, j excluded)
36 * according to a uniform distribution.
7+ *
8+ * @function
9+ * @param {number } i The inclusive left bound
10+ * @param {number } j The non-inclusive right bound
11+ * @return {number } An integer in the interval [i, j[ taken uniformly at
12+ * random.
413 */
5-
6- const randint = ( i , j ) => i + Math . floor ( Math . random ( ) * ( j - i ) ) ;
14+ const randint = _randint ( random ) ;
715export default randint ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Returns a double in the interval [0, 1) using JavaScript Math.random().
3+ * @return {number }
4+ */
5+ const random = ( ) => {
6+ return Math . random ( ) ;
7+ } ;
8+
9+ export default random ;
Original file line number Diff line number Diff line change 11export { default as randfloat } from './api/randfloat.js' ;
22export { default as randint } from './api/randint.js' ;
3+ export { default as random } from './api/random.js' ;
34export { default as randrange } from './api/randrange.js' ;
45export { default as sample } from './api/sample.js' ;
56export { default as shuffle } from './api/shuffle.js' ;
67export { default as _fisheryates } from './kernel/_fisheryates.js' ;
8+ export { default as _randfloat } from './kernel/_randfloat.js' ;
9+ export { default as _randint } from './kernel/_randint.js' ;
710export { default as _shuffle } from './kernel/_shuffle.js' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Builds a randfloat function given a random number generator.
3+ *
4+ * @param {Function } random A function taking no arguments that returns a
5+ * double uniformly at random in the interval [0, 1).
6+ *
7+ * @return {Function } A randfloat function.
8+ */
9+ const _randfloat = ( random ) => {
10+ /**
11+ * Returns a double in interval [i, j[ (i included, j excluded)
12+ * according to a uniform distribution.
13+ *
14+ * @param {number } i The inclusive left bound
15+ * @param {number } j The non-inclusive right bound
16+ * @return {number } A double in the interval [i, j[ taken uniformly at
17+ * random.
18+ */
19+ const randfloat = ( i , j ) => i + random ( ) * ( j - i ) ;
20+ return randfloat ;
21+ } ;
22+
23+ export default _randfloat ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Builds a randint function given a random number generator.
3+ *
4+ * @param {Function } random A function taking no arguments that returns a
5+ * double uniformly at random in the interval [0, 1).
6+ *
7+ * @return {Function } A randint function.
8+ */
9+ const _randint = ( random ) => {
10+ /**
11+ * Returns an integer in interval [i, j[ (i included, j excluded)
12+ * according to a uniform distribution.
13+ *
14+ * @param {number } i The inclusive left bound
15+ * @param {number } j The non-inclusive right bound
16+ * @return {number } An integer in the interval [i, j[ taken uniformly at
17+ * random.
18+ */
19+ const randint = ( i , j ) => i + Math . floor ( random ( ) * ( j - i ) ) ;
20+ return randint ;
21+ } ;
22+
23+ export default _randint ;
You can’t perform that action at this time.
0 commit comments