diff --git a/lib/node_modules/@stdlib/utils/tabulate-by/README.md b/lib/node_modules/@stdlib/utils/tabulate-by/README.md index 493939436df5..c44e0a8ff0ca 100644 --- a/lib/node_modules/@stdlib/utils/tabulate-by/README.md +++ b/lib/node_modules/@stdlib/utils/tabulate-by/README.md @@ -127,15 +127,14 @@ The returned frequency table is an `array` of `arrays`. Each sub-array correspon ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var take = require( '@stdlib/array/take' ); var tabulateBy = require( '@stdlib/utils/tabulate-by' ); var vals; +var indices; var arr; var out; -var i; -var j; function indicator( value ) { return value[ 0 ]; @@ -143,12 +142,11 @@ function indicator( value ) { vals = [ 'beep', 'boop', 'foo', 'bar', 'woot', 'woot' ]; -// Generate a random collection... -arr = []; -for ( i = 0; i < 100; i++ ) { - j = floor( randu()*vals.length ); - arr.push( vals[ j ] ); -} +// Generate a list of random indices: +indices = discreteUniform( 100, 0, vals.length - 1 ); + +// Create a random collection by picking elements at the generated indices: +arr = take( vals, indices ); // Generate a frequency table: out = tabulateBy( arr, indicator ); diff --git a/lib/node_modules/@stdlib/utils/tabulate-by/examples/index.js b/lib/node_modules/@stdlib/utils/tabulate-by/examples/index.js index 05eb907e5f70..edbb19c94b83 100644 --- a/lib/node_modules/@stdlib/utils/tabulate-by/examples/index.js +++ b/lib/node_modules/@stdlib/utils/tabulate-by/examples/index.js @@ -18,15 +18,14 @@ 'use strict'; -var randu = require( '@stdlib/random/base/randu' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var take = require( '@stdlib/array/take' ); var tabulateBy = require( './../lib' ); var vals; +var indices; var arr; var out; -var i; -var j; function indicator( value ) { return value[ 0 ]; @@ -34,12 +33,11 @@ function indicator( value ) { vals = [ 'beep', 'boop', 'foo', 'bar', 'woot', 'woot' ]; -// Generate a random collection... -arr = []; -for ( i = 0; i < 100; i++ ) { - j = floor( randu()*vals.length ); - arr.push( vals[ j ] ); -} +// Generate a list of random indices: +indices = discreteUniform( 100, 0, vals.length - 1 ); + +// Create a random collection by picking elements at the generated indices: +arr = take( vals, indices ); // Generate a frequency table: out = tabulateBy( arr, indicator );