Check out example codes for "crypto npm random bytes". It will help you in understanding the concepts better.

Code Example 1

// Asynchronous
const crypto = require('crypto');
crypto.randomBytes(256, (err, buf) => {
  if (err) throw err;
  console.log(`${buf.length} bytes of random data: ${buf.toString('hex')}`);
});

Learn ReactJs, React Native from akashmittal.com