To bookmark, press:
Cmd + D
Bookmark

Rando.js

The world's easiest, most powerful random function.
Plain JavaScript npm for Node.js
Whoops! Please copy manually.

How to use

If you're using plain JavaScript, paste the script tag provided above into the head of your HTML document. If you're using Node.js, use the "npm i..." install command provided above to import Rando.js; then paste the subsequently provided "require" line at the top of your Node.js code. And then- WHAM! Just like that, you're ready to use all of these simple, cryptographically strong commands in your code:

numbers

rando()
Returns a floating-point number between 0 and 1 (could be exactly 0, but never exactly 1).
rando(5)
Returns an integer between 0 and 5 (could be 0 or 5).
rando(5, 10)
Returns an integer between 5 and 10 (could be 5 or 10).
rando(5, "float")
Returns a floating-point number between 0 and 5 (could be exactly 0, but never exactly 5).
rando(5, 10, "float")
Returns a floating-point number between 5 and 10 (could be exactly 5, but never exactly 10).

booleans

rando(true, false)
Returns either true or false.

arrays

rando(["duck", "duck", "goose"])
Returns {index:..., value:...} object representing a value of the provided array OR false if array is empty.

objects

rando({name: "Chuck Norris", roundhouse: true, age: "functionally immortal"})
Returns {key:..., value:...} object representing a property of the provided object OR false if object has no properties.

jQuery elements

rando($("div"))
Returns {index:..., value:...} object representing a jQuery element from the provided jQuery element set OR false if the provided jQuery element set does not contain any elements.

strings

rando("gee willikers!")
Returns a character from the provided string OR false if the string is empty. Reoccurring characters will naturally form a more likely return value.

invalid parameters

rando(null)
Returns false.

Prevent repetitions

By grabbing a sequence and looping through it.

numbers

randoSequence(5)
Returns an array of integers from 0 through 5 in random order.
randoSequence(5, 10)
Returns an array of integers from 5 through 10 in random order.

arrays

randoSequence(["eeny", "meeny", "miny", "moe"])
Returns array of {index:..., value:...} objects representing the values of the provided array in random order.

objects

randoSequence({species: "mouse", blind: true, count: 3})
Returns array of {key:..., value:...} objects representing the properties of the provided object in random order.

jQuery elements

randoSequence($("input"))
Returns array of {index:..., value:...} objects representing all jQuery elements from the provided jQuery element set in random order.

strings

randoSequence("Good gravy!")
Returns the characters of the provided string in random order.

invalid parameters

randoSequence(null)
Returns false.
Star us on GitHub