Initial commit

This commit is contained in:
Developer
2025-04-21 16:03:20 +02:00
commit 2832896157
22874 changed files with 3092801 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
language: node_js
node_js:
- "6"
- "4"
- "0.12"
- "0.10"

View File

@@ -0,0 +1,17 @@
module.exports = (function (global) {
var uint32 = 'Uint32Array' in global
var crypto = global.crypto || global.msCrypto
var rando = crypto && typeof crypto.getRandomValues === 'function'
var good = uint32 && rando
if (!good) return Math.random
var arr = new Uint32Array(1)
var max = Math.pow(2, 32)
function random () {
crypto.getRandomValues(arr)
return arr[0] / max
}
random.cryptographic = true
return random
})(typeof self !== 'undefined' ? self : window)

View File

@@ -0,0 +1,13 @@
var crypto = require('crypto')
var max = Math.pow(2, 32)
module.exports = random
module.exports.cryptographic = true
function random () {
var buf = crypto
.randomBytes(4)
.readUInt32BE(0)
return buf / max
}

View File

@@ -0,0 +1,51 @@
{
"_from": "math-random@^1.0.1",
"_id": "math-random@1.0.4",
"_inBundle": false,
"_integrity": "sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==",
"_location": "/math-random",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "math-random@^1.0.1",
"name": "math-random",
"escapedName": "math-random",
"rawSpec": "^1.0.1",
"saveSpec": null,
"fetchSpec": "^1.0.1"
},
"_requiredBy": [
"/randomatic"
],
"_resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.4.tgz",
"_shasum": "5dd6943c938548267016d4e34f057583080c514c",
"_spec": "math-random@^1.0.1",
"_where": "D:\\developments\\teaser-inertia\\nova-components\\NovaLeader\\node_modules\\randomatic",
"author": {
"name": "Michael Rhodes"
},
"browser": "browser.js",
"bugs": {
"url": "https://github.com/michaelrhodes/math-random/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "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.",
"devDependencies": {
"array-unique": "~0.2.1",
"dexy": "github:michaelrhodes/dexy#1.0.1"
},
"homepage": "https://github.com/michaelrhodes/math-random#readme",
"license": "MIT",
"main": "node.js",
"name": "math-random",
"repository": {
"type": "git",
"url": "git+https://github.com/michaelrhodes/math-random.git"
},
"scripts": {
"test": "dexy test.js"
},
"version": "1.0.4"
}

View File

@@ -0,0 +1,26 @@
# 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.
[![Build status](https://travis-ci.org/michaelrhodes/math-random.svg?branch=master)](https://travis-ci.org/michaelrhodes/math-random)
## Install
```sh
npm install math-random
```
### Usage
```js
var random = require('math-random')
console.log(random())
=> 0.584293719381094
console.log(random.cryptographic)
=> true || undefined
```
### License
[MIT](http://opensource.org/licenses/MIT)

View File

@@ -0,0 +1,21 @@
var assert = console.assert
var unique = require('array-unique')
var random = require('./')
var iterations = 10000
var number, 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')
break
}
if (number >= 1) {
assert(false, 'Random numbers should be less than one')
break
}
cache.push(number)
}
assert(unique(cache).length === iterations, 'Random numbers should be unique')