Files
common/packages/util-crypto/docs/random.md
T
Jaco Greeff b5c5734c7c Add Blake2s & XXHash utility functions (#66)
* Initial split of util & util-crypto

* Add initial XXHash version

* Blake2s wit tests & documentation

* Add sha512 (from NaCl)

* Add randomBytes (from NaCl)

* Flow fixes

* Update documentation

* Update latest @polkadot/dev
2018-01-25 14:13:43 +01:00

1.5 KiB

random

Returns a sequence of secure random bytes in a variety of formats

randomAsBuffer

Creates a Buffer filled with random bytes.

randomAsBuffer (length?: number = 32): Buffer

Returns a Buffer with the specified (optional) length filled with random bytes.

import { randomAsBuffer } from '@polkadot/util-crypto';

randomAsBuffer() // => Buffer([...])

randomAsHex

Creates a hex string filled with random bytes.

randomAsHex (length?: number = 32): string

Returns a hex string with the specified (optional) length filled with random bytes.

import { randomAsHex } from '@polkadot/util-crypto';

randomAsHex() // => 0x...

randomAsNumber

Creates a random number from random bytes.

randomAsNumber (): number

Returns a random number generated from the secure bytes.

import { randomAsNumber } from '@polkadot/util-crypto';

randomAsNumber() // => <random number>

randomAsU8a

Creates a Uint8Array filled with random bytes.

randomAsU8a (length?: number = 32): Uint8Array

Returns a Uint8Array with the specified (optional) length filled with random bytes.

import { randomAsU8a } from '@polkadot/util-crypto';

randomAsU8s() // => Uint8Array([...])