Skip to content

frob/randomcrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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.

Constants

NORMAL_BIAS : Number

The Normal Bias needed to create centered Random Number Generation.

HIGH_ADJUSTER : Number

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

LOW_ADJUSTER : Number

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

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])

Param Type Default Description
[biasAdjuster] Float "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

Param Type Default Description
[bias] Float "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

Param Type Default Description
set Array The set from which to pull a random element.
[name] String "__default" The name of the set, if this is set then the random element will be removed as a possible element in future calls.
[loop] Boolean "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

Param Type Default Description
options Object Optional arguments.
[options.allCaps] Boolean "false" Only return Capitalized letters.
[options.noCaps] Boolean "false" Never return Capitalized letters.
[options._set] Array "[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

Param Type Description
wholePrecision Integer The number of precision to the left of the decimal point.
floatPrecision Integer The 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

Param Type Description
min Integer The lowest number to return.
max Integer The 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

About

A npm js module that creates random things.

Resources

Stars

Watchers

Forks

Packages

No packages published