mardi 19 janvier 2016

Get random long using npm package

In Nodejs, using documentation from npm long and having this code:

var Long = require("long");
...
console.log(Long.NEG_ONE);
console.log(Math.random());
console.log(Long.MAX_VALUE);
console.log(Long.MAX_VALUE.multiply(Math.random()));
console.log(new Long(Math.random() * Long.MAX_VALUE));

prints:

{ low: -1, high: -1, unsigned: false }
0.8203735549468547
{ low: -1, high: 2147483647, unsigned: false }
{ low: 0, high: 0, unsigned: false }
{ low: 0, high: 0, unsigned: false }

What I basically need is to get the random long number in js. How one could be generated?




Aucun commentaire:

Enregistrer un commentaire