1.3.0 • Published 8 years ago

randomcrap v1.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

randomcrap

This is a dependency free random crap generator. Currently it handles getting random simple random ints, but I will be adding stuff to it as I need it for my other projects.

This has more entropy than Math.random() but isn't going to be adequate for crypto. For that I suggest GRC javascript peudo-random number generator or Web Cryptography API.

Planned additions

  • random int
  • random from set
  • random float
  • random alpha
  • random alpha numeric
  • random emoji

API

This is meant to be a flexible yet not cryptography sound random number generator. The numbers should look good, and the bias is adjustable. A high bias will yield higher random numbers from sets. This bias can be set through the constructor or through a setter function.

Classes

Constants

RandomCrap

Class for generation of RandomCrap.

Please do not complain about these numbers not being "true" random. The point behind doing this isn't to have correct math, but instead to generate numbers that are fun. This is why the bais exists and can be adjusted. This way the developer can influence the result to adjust the fun.

Kind: global class

new RandomCrap(biasAdjuster)

ParamTypeDefaultDescription
biasAdjusterFloat"NORMAL_BIAS"Allows setting a high or low bias for random generation.

randomCrap.setBias(bias)

Sets the current random bias.

Kind: instance method of RandomCrap

ParamTypeDefaultDescription
biasFloat"NORMAL_BIAS"Allows setting a high or low bias for random generation. Setting nothing will reset to neutral bias.

randomCrap.getBias() ⇒ Boolean

Returns the current bias.

Kind: instance method of RandomCrap

randomCrap.randomFrom(set, name, loop)

Gets a random element from a supplied set.

Kind: instance method of RandomCrap

ParamTypeDefaultDescription
setArrayThe set from which to pull a random element.
nameString"__default"The name of the set, if this is set then the random element will be removed as a possible element in future calls.
loopBoolean"false"Append the original set back onto the end if the set is empty.

randomCrap.simpleRandomAlpha(options) ⇒ String

Returns a random alpha character.

Kind: instance method of RandomCrap

ParamTypeDefaultDescription
optionsObjectOptional arguments.
options.allCapsBoolean"false"Only return Capitalized letters.
options.noCapsBoolean"false"Never return Capitalized letters.
options._setArray"a, b, c, ... z"Inject set, useful for testing, or localization.

randomCrap.simpleRandomFloat(wholePrecision, floatPrecision) ⇒ Float

Returns a simple random floating point Number.

Kind: instance method of RandomCrap

ParamTypeDescription
wholePrecisionIntegerThe number of precision to the left of the decimal point.
floatPrecisionIntegerThe number of precision to the right of the decimal point.

randomCrap.simpleRandomInt(min, max) ⇒ Integer

Returns a random integer from min (inclusive) to max (inclusive).

Kind: instance method of RandomCrap

ParamTypeDescription
minIntegerThe lowest number to return.
maxIntegerThe highest number to return.

NORMAL_BIAS : Number

The Normal Bias needed to create centered Random Number Generation.

Kind: global constant

HIGH_ADJUSTER : Number

The High end on which the random number will be adjusted for randomness.

Kind: global constant

LOW_ADJUSTER : Number

The High end on which the random number will be adjusted for randomness.

Kind: global constant

1.3.0

8 years ago

1.2.0

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.0.0

8 years ago