All Projects → bramp → Prob.js

bramp / Prob.js

Licence: apache-2.0
Generate random numbers from different probability distributions.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Prob.js

Minecraft Randomiser
Resource pack and data pack randomiser to shuffle textures, sounds, loot tables, recipes, and more
Stars: ✭ 34 (-66.67%)
Mutual labels:  random
Pgen
Command-line passphrase generator
Stars: ✭ 68 (-33.33%)
Mutual labels:  random
Birdseed
🐦 🎲 Use Twitter's Search API to get random numbers
Stars: ✭ 81 (-20.59%)
Mutual labels:  random
Randomdatagenerator
This is a configurable generator to create random data like Lorum Ipsum Text, Words, Text Patterns, First/Last Names, MAC-Addresses, IP-Addresses, Guids and DateTime.
Stars: ✭ 45 (-55.88%)
Mutual labels:  random
Kirby3 Autoid
Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
Stars: ✭ 58 (-43.14%)
Mutual labels:  random
Random Bytes Readable Stream
Creates a readable stream producing cryptographically strong pseudo-random data using `crypto.randomBytes()`
Stars: ✭ 71 (-30.39%)
Mutual labels:  random
Rasusa
Randomly subsample sequencing reads to a specified coverage
Stars: ✭ 28 (-72.55%)
Mutual labels:  random
Weightedrand
⚖️ Fast weighted random selection for Go
Stars: ✭ 96 (-5.88%)
Mutual labels:  random
Easy Random
The simple, stupid random Java beans/records generator
Stars: ✭ 1,095 (+973.53%)
Mutual labels:  random
Eth Random
commit-reveal RNG method in Ethereum
Stars: ✭ 79 (-22.55%)
Mutual labels:  random
Troschuetz.random
Fully managed library providing various random number generators and distributions.
Stars: ✭ 47 (-53.92%)
Mutual labels:  random
Yesterday I Learned
Brainfarts are caused by the rupturing of the cerebral sphincter.
Stars: ✭ 50 (-50.98%)
Mutual labels:  random
Random Word
This is a simple python package to generate random english words
Stars: ✭ 75 (-26.47%)
Mutual labels:  random
Wyhash Rs
wyhash fast portable non-cryptographic hashing algorithm and random number generator in Rust
Stars: ✭ 44 (-56.86%)
Mutual labels:  random
Randomcolor
Javascript module for generating random, distinguishable, pleasing colors (ie: for chart series).
Stars: ✭ 83 (-18.63%)
Mutual labels:  random
Mir Random
Advanced Random Number Generators
Stars: ✭ 30 (-70.59%)
Mutual labels:  random
Random
Generate random strings or numeric values
Stars: ✭ 68 (-33.33%)
Mutual labels:  random
Octo
A fuzzing library in JavaScript. ✨
Stars: ✭ 96 (-5.88%)
Mutual labels:  random
Keygen Php
A fluent PHP random key generator.
Stars: ✭ 93 (-8.82%)
Mutual labels:  random
Spicy Proton
Generate a random English adjective-noun word pair in Ruby
Stars: ✭ 76 (-25.49%)
Mutual labels:  random

Prob.js bower npm LICENSE

by Andrew Brampton 2016

Generate random numbers from different probability distributions. Demo.

Use

Bower:

bower install prob.js
<script src="bower_components/random/lib/random.min.js" type="text/javascript" ></script>
<script src="bower_components/prob.js/dist/prob-min.js" type="text/javascript" ></script>

Node.js:

npm install prob.js
var Prob = require('prob.js');

Example:

var r = Prob.normal(0, 1.0); // μ = 0, σ = 1.0 
r(); // Returns a random number from this distribution
r(); // Returns another random number
r(); // and again

API

The following distribution are available:

Prob.uniform(min, max) // Uniform distribution in range [min, max).
Prob.normal(μ, σ)      // Normal distribution with mean and standard deviation.
Prob.exponential(λ)    // Exponential distribution with lambda.
Prob.lognormal(μ, σ)   // Log-normal distribution defined as ln(normal(μ, σ)).
Prob.poisson(λ)        // Poisson distribution returning integers >= 0.
Prob.zipf(s, N)        // Zipf's distribution returning integers in range [1, N].

After generating a distribution, the following methods are available:

var r = Prob.exponential(1.0); // Create a distribution.
r()        // Generates a number within the distribution.
r(src)     // Generates a number using a `src` of random numbers. (See note below.)
r.Min      // The min random number which could be returned by `r()` (inclusive).
r.Max      // The max random number which could be returned by `r()` (exclusive).
r.Mean     // The expected mean for this distribution.
r.Variance // The expected variance for this distribution.

Random source

Internally Prob.js uses Mersenne Twister provided by random-js. This can be overridden by providing the src argument when generating a number. src is expected to be a function that when called returns a signed integer uniformly in the range [-2^31,2^31).

For example:

// https://xkcd.com/221/
function xkcd_source() {
	return 4; // chosen by fair dice roll.
	          // guaranteed to be random.
};

var r = Prob.exponential(1.0); // Create a distribution.

// Use the XKCD source
console.log( r(xkcd_source) );

// Or use a better source (supplied by random-js)
console.log( r(Random.engines.browserCrypto) );

// Or just use the default which happens to be Random.engines.mt19937().autoSeed()
console.log( r() );

How to release

make clean && make   # Build and test once
mversion patch       # Bump version number (v1.2.3 | major | minor | patch)
make clean && make   # Be extra sure after the version bump it continues to work

git add -f bower.json package.json dist/{prob-min.js,prob-min.js.map,prob.js}
VERSION=v`mversion | tail -n 1 | cut -d ' ' -f 2`
git commit -m "Releasing version $VERSION"
git tag $VERSION
git push origin
git push origin --tags

npm publish          # Publish to npm (publishing to bower is not needed)

Licence (Apache 2)

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

Copyright 2016 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].