ngraph.random
Operation with seeded random numbers for ngraph.*.
Install
You can use CDN:
or via npm:
npm install ngraph.random
and then:
var ngraphRandom =
Usage
API provides random number generation, and array shuffling.
Let's start with random number generation:
// create generator, seeded with 42var randomGenerator = ;// prints double number from [0..1)console;// Get next non-negative random number, less than 100.console; // prints 20, we are seeded// Note: next() always expect maxValue. If you don't pass it it will return NaN.// This is done for performance reasons, we don't want to check input arguments// on each call.
Second part of the API is array shuffling:
var ngraphRandom = ;// create "shuffling" iterator:var originalArray = 0 1 2 3 4 5;var randomIterator = ngraphRandom;// iterate over array in random order:randomIterator;// Note: using random iterator does modify original array.// This is done to save memory.// If you want to re-shuffle array in-place, you can use:randomIterator;// Finally if you want to have seeded shuffling you can pass optional seeded// random number generator:var seededGenerator = ngraphRandom;ngraphRandom;
distributions
The library supports random number generation that follow Gaussian distribution:
var generator = ;// returns a random number from a gaussian distribution with mean 0 and// standard deviation 1generator;
License
BSD 3-clause