Skip to content

Commit 8e110d6

Browse files
docs: update examples for random/array/tools
PR-URL: #2670 Closes: #1605 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent a8b0d58 commit 8e110d6

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

lib/node_modules/@stdlib/random/array/tools/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,31 @@ The namespace contains the following:
6565

6666
## Examples
6767

68-
<!-- TODO: better examples -->
69-
7068
<!-- eslint no-undef: "error" -->
7169

7270
```javascript
73-
var objectKeys = require( '@stdlib/utils/keys' );
71+
var exponential = require( '@stdlib/random/base/exponential' );
72+
var arcsine = require( '@stdlib/random/base/arcsine' );
73+
var randn = require( '@stdlib/random/base/improved-ziggurat' );
7474
var ns = require( '@stdlib/random/array/tools' );
7575

76-
console.log( objectKeys( ns ) );
76+
// Create a binary PRNG array:
77+
var dtypes = [ 'float64', 'float32', 'generic' ];
78+
var defaultDType = 'float64';
79+
80+
var rand = new ns.binary( arcsine, dtypes, defaultDType );
81+
var x = rand.generate( 10, 2.0, 5.0 );
82+
// e.g., returns <Float64Array>[ ~3.65, ~4.34, ~3.52, ~4.68, ~2.62, ... ]
83+
84+
// Create a unary PRNG array:
85+
rand = new ns.unary( exponential, dtypes, defaultDType );
86+
x = rand.generate( 10, 0.5 );
87+
// e.g., returns <Float64Array>[ ~0.22, ~2.89, ~0.69, ~2.48, ~0.82, ... ]
88+
89+
// Create a nullary PRNG array:
90+
rand = new ns.nullary( randn, dtypes, defaultDType );
91+
x = rand.generate( 10 );
92+
// e.g., returns <Float64Array>[ ~-0.22, ~1.89, ~-0.69, ~0.48, ~-0.82, ... ]
7793
```
7894

7995
</section>

lib/node_modules/@stdlib/random/array/tools/examples/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,28 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
21+
var exponential = require( '@stdlib/random/base/exponential' );
22+
var arcsine = require( '@stdlib/random/base/arcsine' );
23+
var randn = require( '@stdlib/random/base/improved-ziggurat' );
2224
var ns = require( './../lib' );
2325

24-
console.log( objectKeys( ns ) );
26+
// Create a binary PRNG array:
27+
var dtypes = [ 'float64', 'float32', 'generic' ];
28+
var defaultDType = 'float64';
29+
30+
var rand = new ns.binary( arcsine, dtypes, defaultDType );
31+
var x = rand.generate( 10, 2.0, 5.0 );
32+
console.log( x );
33+
// e.g., => <Float64Array>[ ~3.65, ~4.34, ~3.52, ~4.68, ~2.62, ... ]
34+
35+
// Create a unary PRNG array:
36+
rand = new ns.unary( exponential, dtypes, defaultDType );
37+
x = rand.generate( 10, 0.5 );
38+
console.log( x );
39+
// e.g., => <Float64Array>[ ~0.22, ~2.89, ~0.69, ~2.48, ~0.82, ... ]
40+
41+
// Create a nullary PRNG array:
42+
rand = new ns.nullary( randn, dtypes, defaultDType );
43+
x = rand.generate( 10 );
44+
console.log( x );
45+
// e.g., => <Float64Array>[ ~-0.22, ~1.89, ~-0.69, ~0.48, ~-0.82, ... ]

0 commit comments

Comments
 (0)