Skip to content

Commit 62bb1e0

Browse files
docs: improve examples of random/array namespace
PR-URL: #1965 Closes: #1604 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 8edb71d commit 62bb1e0

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,46 @@ The namespace contains the following:
9595

9696
## Examples
9797

98-
<!-- TODO: better examples -->
99-
10098
<!-- eslint no-undef: "error" -->
10199

102100
```javascript
103-
var objectKeys = require( '@stdlib/utils/keys' );
104101
var ns = require( '@stdlib/random/array' );
105102

106-
console.log( objectKeys( ns ) );
103+
// Generate arrays with ten random numbers drawn from the respective distributions:
104+
var out = ns.arcsine( 10, 2.0, 5.0 );
105+
// returns <Float64Array>
106+
107+
out = ns.weibull( 10, 2.0, 5.0 );
108+
// returns <Float64Array>
109+
110+
out = ns.laplace( 10, 2.0, 5.0 );
111+
// returns <Float64Array>
112+
113+
// Factory methods:
114+
115+
// 1. Basic factory usage (no parameters):
116+
var random = ns.arcsine.factory();
117+
out = random( 10, 2.0, 5.0 );
118+
// returns <Float64Array>
119+
120+
// 2. Factory with options (e.g., seed):
121+
random = ns.arcsine.factory({
122+
'seed': 1234
123+
});
124+
out = random( 10, 2.0, 5.0 );
125+
// returns <Float64Array>
126+
127+
// 3. Factory with distribution parameters:
128+
random = ns.arcsine.factory( 2.0, 5.0 );
129+
out = random( 10 );
130+
// returns <Float64Array>
131+
132+
// 4. Factory with both distribution parameters and options:
133+
random = ns.arcsine.factory( 2.0, 5.0, {
134+
'dtype': 'float32'
135+
});
136+
out = random( 10 );
137+
// returns <Float32Array>
107138
```
108139

109140
</section>

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

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

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
2221
var ns = require( './../lib' );
2322

24-
console.log( objectKeys( ns ) );
23+
// Generate arrays with ten random numbers drawn from the respective distributions:
24+
var out = ns.arcsine( 10, 2.0, 5.0 );
25+
console.log( out );
26+
// => <Float64Array>
27+
28+
out = ns.weibull( 10, 2.0, 5.0 );
29+
console.log( out );
30+
// => <Float64Array>
31+
32+
out = ns.laplace( 10, 2.0, 5.0 );
33+
console.log( out );
34+
// => <Float64Array>
35+
36+
// Factory methods:
37+
38+
// 1. Basic factory usage (no parameters):
39+
var random = ns.arcsine.factory();
40+
out = random( 10, 2.0, 5.0 );
41+
console.log( out );
42+
// => <Float64Array>
43+
44+
// 2. Factory with options (e.g., seed):
45+
random = ns.arcsine.factory({
46+
'seed': 1234
47+
});
48+
out = random( 10, 2.0, 5.0 );
49+
console.log( out );
50+
// => <Float64Array>
51+
52+
// 3. Factory with distribution parameters:
53+
random = ns.arcsine.factory( 2.0, 5.0 );
54+
out = random( 10 );
55+
console.log( out );
56+
// => <Float64Array>
57+
58+
// 4. Factory with both distribution parameters and options:
59+
random = ns.arcsine.factory( 2.0, 5.0, {
60+
'dtype': 'float32'
61+
});
62+
out = random( 10 );
63+
console.log( out );
64+
// => <Float32Array>

0 commit comments

Comments
 (0)