Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

math-random

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

math-random - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

browser/crypto.js

13

node.js

@@ -1,13 +0,10 @@

var crypto = require('crypto')
module.exports = random
var crypto = require('./crypto')
var max = Math.pow(2, 32)
module.exports = random
module.exports.cryptographic = true
function random () {
var buf = crypto
return crypto
.randomBytes(4)
.readUInt32BE(0)
return buf / max
.readUInt32BE(0) / max
}
{
"name": "math-random",
"author": "Michael Rhodes",
"version": "1.0.4",
"main": "node.js",
"browser": "browser.js",
"version": "2.0.0",
"main": "node",
"browser": {
"./node": "./browser/index",
"./crypto": "./browser/crypto"
},
"repository": "github:michaelrhodes/math-random",
"license": "MIT",
"scripts": {
"test": "dexy test.js"
},
"license": "CC0-1.0",
"devDependencies": {
"array-unique": "~0.2.1",
"dexy": "github:michaelrhodes/dexy#1.0.1"
"dexy": "github:michaelrhodes/dexy#1.0.4"
},
"scripts": {
"test": "dexy test"
}
}
# math-random
math-random is an drop-in replacement for Math.random that uses cryptographically secure random number generation, where available. It works in both browser and node environments.
math-random is an isomorphic, drop-in replacement for `Math.random` that uses cryptographically secure random number generation, where available
[![Build status](https://travis-ci.org/michaelrhodes/math-random.svg?branch=master)](https://travis-ci.org/michaelrhodes/math-random)
[![ci](https://travis-ci.org/michaelrhodes/math-random.svg?branch=master)](https://travis-ci.org/michaelrhodes/math-random)
## Install
## install
```sh

@@ -13,15 +12,12 @@ npm install math-random

### Usage
### use
```js
var random = require('math-random')
console.log(random())
console.log(require('math-random')())
=> 0.584293719381094
console.log(random.cryptographic)
=> true || undefined
console.log(require('math-random/is-secure'))
=> true || false
```
### License
[MIT](http://opensource.org/licenses/MIT)
### obey
[CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/)

@@ -1,21 +0,29 @@

var assert = console.assert
var random = require('./')
var unique = require('array-unique')
var random = require('./')
var iterations = 10000
var number, cache = []
var n, cache = []
for (var i = 0; i < iterations; i++) {
number = random()
if (number < 0) {
assert(false, 'Random numbers should be greater than or equal to zero')
n = random()
if (typeof n !== 'number') {
fail('Random numbers should be numbers')
break
}
if (number >= 1) {
assert(false, 'Random numbers should be less than one')
if (n < 0) {
fail('Random numbers should be greater than or equal to zero')
break
}
cache.push(number)
if (n >= 1) {
fail('Random numbers should be less than one')
break
}
cache.push(n)
}
assert(unique(cache).length === iterations, 'Random numbers should be unique')
if (unique(cache).length !== iterations) {
fail('Random numbers should be unique')
}
function fail (msg) {
console.assert(false, msg)
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc