Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including random-bytes-js with all npm packages installed. Try it out:

var randomBytesJs = require("random-bytes-js")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

random-bytes-js v1.0.0

pseudo random bytes in javascript for the browser

random-bytes-js

pseudo random bytes in javascript for the browser

demo: https://angeal185.github.io/random-bytes-js

Installation

npm

$ npm install random-bytes-js --save

bower

$ bower install random-bytes-js

git

$ git clone git@github.com:angeal185/random-bytes-js.git

browser

<script src="./dist/random-bytes.min.js"></script>

nodejs

const rbjs = require('random-bytes-js')

API


/**
 *  @param {integer} int ~ bytes length
 *  @param {function} cb ~ optional callback function(err,res)
 **/

// random bytes as string
rbjs.rand(int, cb)

// random bytes as Uint8 array
rbjs.randUint8(int, cb)

// random bytes as numbered array
rbjs.randArr(int, cb)

// random bytes as numbered string
rbjs.randNumStr(int, cb)

// random bytes to hex
rbjs.randHex(int, cb)

// random bytes to base64
rbjs.rand64(int, cb)


//demo

let sync;

sync = rbjs.rand(10);
console.log(sync)

rbjs.rand(10, function(err, res){
  if(err){return console.log(err)}
  console.log(res)
})


sync = rbjs.randUint8(10);
console.log(sync)

rbjs.randUint8(10, function(err, res){
  if(err){return console.log(err)}
  console.log(res)
})


sync = rbjs.randArr(10);
console.log(sync)

rbjs.randArr(10, function(err, res){
  if(err){return console.log(err)}
  console.log(res)
})


sync = rbjs.randNumStr(10);
console.log(sync)

rbjs.randNumStr(10, function(err, res){
  if(err){return console.log(err)}
  console.log(res)
})


sync = rbjs.randHex(10);
console.log(sync)

rbjs.randHex(10, function(err, res){
  if(err){return console.log(err)}
  console.log(res)
})


sync = rbjs.rand64(10);
console.log(sync)

rbjs.rand64(10, function(err, res){
  if(err){return console.log(err)}
  console.log(res)
})


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free