UNPKG

793 BMarkdownView Raw
1randomHex
2===
3
4Will create a random bytes HEX string, in node.js and browsers with crypto.
5
6This library uses the [crypto.randomBytes()](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback) in node.js,
7and [crypto.getRandomValues()](https://developer.mozilla.org/en/docs/Web/API/RandomSource/getRandomValues) in the browser.
8
9Both of those random generators should provide cryptographically strong pseudo-random data.
10
11```
12$ npm install randomhex
13```
14
15
16
17```js
18var randomHex = require('randomhex');
19
20randomHex(16); // get 16 random bytes as HEX string (0x + 32 chars)
21> "0xd59e72dbf8612798aa1674834c80894e"
22
23randomHex(32, console.log); // get 32 random bytes as HEX string (0x + 64 chars)
24> null "0x409de75fc727d81a7d9f59580130ce3e76124679eb5c4647eb18c40512450c29"
25
26```