Skip to content

Commit e35173c

Browse files
committed
docs: update examples
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 4a75382 commit e35173c

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ limitations under the License.
2727
## Usage
2828

2929
```javascript
30-
var random = require( '@stdlib/random' );
30+
var ns = require( '@stdlib/random' );
3131
```
3232

33-
#### random
33+
#### ns
3434

3535
Namespace containing random number functionality.
3636

3737
```javascript
38-
var rand = random;
39-
// returns {...}
38+
var arr = ns.normal( [ 3, 3 ], 2.0, 5.0 );
39+
// returns <ndarray>
4040
```
4141

4242
The namespace exports the following functions to sample and shuffle elements from an array:
@@ -82,15 +82,42 @@ The namespace contains the following sub-namespaces:
8282

8383
## Examples
8484

85-
<!-- TODO: better examples -->
86-
8785
<!-- eslint no-undef: "error" -->
8886

8987
```javascript
90-
var objectKeys = require( '@stdlib/utils/keys' );
88+
var logEach = require( '@stdlib/console/log-each' );
89+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
9190
var ns = require( '@stdlib/random' );
9291

93-
console.log( objectKeys( ns ) );
92+
// Create a function for generating arrays originating from the same state:
93+
var random = ns.normal.factory({
94+
'state': ns.normal.state,
95+
'copy': true
96+
});
97+
98+
// Generate 3 one-dimensional arrays:
99+
var x1 = random( [ 5 ], 2.0, 5.0 );
100+
var x2 = random( [ 5 ], 2.0, 5.0 );
101+
var x3 = random( [ 5 ], 2.0, 5.0 );
102+
103+
// Print the contents:
104+
logEach( '%f, %f, %f', ndarray2array( x1 ), ndarray2array( x2 ), ndarray2array( x3 ) );
105+
106+
// Create another function for generating random arrays with the original state:
107+
random = ns.normal.factory({
108+
'state': ns.normal.state,
109+
'copy': true
110+
});
111+
112+
// Generate a two-dimensional array which replicates the above pseudorandom number generation sequence:
113+
var x4 = random( [ 3, 5 ], 2.0, 5.0 );
114+
115+
// Convert to a list of nested arrays:
116+
var arr = ndarray2array( x4 );
117+
118+
// Print the contents:
119+
console.log( '' );
120+
logEach( '%f, %f, %f', arr[ 0 ], arr[ 1 ], arr[ 2 ] );
94121
```
95122

96123
</section>

0 commit comments

Comments
 (0)