Zero-dep package to generate random bytes using a seed.
npm install @csquare/random-bytes-seed@csquare/random-bytes-seed


Zero-dependency package to generate seeded random bytes; TypeScript typings included.
Maintained by Mathieu Bour, Lead Platform Engineer
at Cohesive Computing SA.
Install with npm:
``shell`
npm install --save @csquare/random-bytes-seed
Install with Yarn:
`shell`
yarn add @csquare/random-bytes-seed
Using CommonJS syntax:
`typescript
const { randomBytesSeed } = require('@csquare/random-bytes-seed');
const output = randomBytesSeed(10, 'my-seed'); // Generate a 10-bytes, stable buffer
`
Using ESM syntax (default import):
`typescript
import randomBytesSeed from '@csquare/random-bytes-seed';
const output = randomBytesSeed(10, 'my-seed'); // Generate a 10-bytes, stable buffer
`
or
`typescript
import { randomBytesSeed } from '@csquare/random-bytes-seed';
const output = randomBytesSeed(10, 'my-seed'); // Generate a 10-bytes, stable buffer
`
If you do not provide a seed, the randomBytesSeed will simply fallbacks to randomBytes.
#### Changing the base seed
By default, this packages uses a base seed equals to random-bytes-seed in conjunction of the given seed. You can
change the base seed by overriding the default options.
`typescript
import { options } from '@csquare/random-bytes-seed';
options.seed = 'any-string-you-want'; // Override the base seed for all future calls
`
#### Changing the hash algorithm
This package use Node createHash function from the crypto module. By default, the rounds are computed withsha256
the hash algorithm. You can change this behavior by overriding the default options.
`typescript
import { options } from '@csquare/random-bytes-seed';
options.algorithm = 'sha512'; // Use sha512 algorithm instead of sh256
`
From the nodejs.org documentation:
> The algorithm is dependent on the available algorithms supported by the version of OpenSSL on the platform.
> Examples are 'sha256', 'sha512', etc.openssl list -digest-algorithms
> On recent releases of OpenSSL, (openssl list-message-digest-algorithms` for older versions of OpenSSL) will display the available digest algorithms.
>
> Reference: https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_options