Generate random IDs and avoid collisions.
var hat = require('hat'); var id = hat(); console.log(id);
var hat = require('hat'); var rack = hat.rack(); console.log(rack()); console.log(rack());
var hat = require('hat');
Generate a random ID string with
bits of data in a
Leading zeros are appended such that all outputs for a given number of bits have equal length.
var rack = hat.rack(bits=128, base=16, expandBy)
Make a new hat rack. Call
rack() repeatedly to generate new IDs which are
checked for collisions.
expandBy is specified, increment
bits by this amount if too many
collisions occur. If
expandBy isn't specified,
rack() will throw if too many
collisions occur during generation.
var id = rack(data) to store
data at the new ID.
You can get the data out again with
rack.get(id) and set the data with
how to make a hat
First you will need a large square of cloth or paper. These materials work well:
- large napkin
If you find yourself at a fancy restaurant, large napkins are in abundant supply.
Tie a knot in each corner. Place the hat on your head and enjoy!