Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions lib/node_modules/@stdlib/random/strided/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,52 @@ The namespace contains the following:
<!-- eslint no-undef: "error" -->

```javascript
var objectKeys = require( '@stdlib/utils/keys' );
var ns = require( '@stdlib/random/strided/tools' );

console.log( objectKeys( ns ) );
var tools = require( '@stdlib/random/strided/tools' );
var uniform = require( '@stdlib/random/base/uniform' );
var normal = require( '@stdlib/random/base/normal' );
var bernoulli = require( '@stdlib/random/base/bernoulli' );
var filled = require( '@stdlib/array/filled' );
var zeros = require( '@stdlib/array/zeros' );
var array = require( '@stdlib/ndarray/array' );

// Create PRNG factories
var uniformFactory = tools.unaryFactory( uniform );
var normalFactory = tools.binaryFactory( normal );
var bernoulliFactory = tools.unaryFactory( bernoulli );

// Create uniform PRNG for filling strided arrays
var uniformFill = uniformFactory( -5.0, 5.0 );

// Create normal PRNG for filling strided arrays
var normalFill = normalFactory( 0.0, 1.0 );

// Create Bernoulli PRNG for filling strided arrays
var bernoulliFill = bernoulliFactory( 0.5 );

// Create arrays to fill
var x = zeros( 10 );
var y = filled( null, 10 );
var z = array( new Float64Array( 10 ), {
'dtype': 'float64'
});

// Fill arrays with random values
uniformFill( x.length, x, 1 );
normalFill( y.length, y, 1 );
bernoulliFill( z.data.length, z.data, 1 );

console.log( 'Uniform (-5, 5):' );
console.log( x );
console.log( '\nNormal (0, 1):' );
console.log( y );
console.log( '\nBernoulli (p=0.5):' );
console.log( z.data );

// Demonstrate stride manipulation
var w = zeros( 20 );
uniformFill( 5, w, 4 );
console.log( '\nUniform with stride 4:' );
console.log( w );
```

</section>
Expand Down
Loading