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. |
Boolean
randomCrap.getBias() ⇒ 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. |
String
randomCrap.simpleRandomAlpha(options) ⇒ 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. |
Float
randomCrap.simpleRandomFloat(wholePrecision, floatPrecision) ⇒ 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. |
Integer
randomCrap.simpleRandomInt(min, max) ⇒ 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. |
Number
NORMAL_BIAS : The Normal Bias needed to create centered Random Number Generation.
Number
HIGH_ADJUSTER : The High end on which the random number will be adjusted for randomness.
Number
LOW_ADJUSTER : The High end on which the random number will be adjusted for randomness.
Kind: global constant