# Generate unique ids and hashes

> Create ids with UID() and GUID(), and hashes with HASH(), and know which one to use where.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: a2d933d0ce2ac0a974dc8fe539259bf770d8fc8c8feedabafebf804b6285bda5
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

- `UID()` creates a short, time-ordered, unique id (12 characters). It sorts by creation time and is what the `UID` input type validates. Use it as the primary key of your documents.
- `GUID(length)` creates a random string of the requested length. Use it for tokens and file names.
- `HASH(value)` returns a fast numeric hash (not cryptographic). Use it for cache keys, ETags and sharding, never for passwords.

```js controllers/ids.js
exports.install = function() {
	ROUTE('GET /ids/', ids);
};

function ids($) {

	var a = UID();
	var b = UID();

	$.json({
		uid: a,
		uidlength: a.length,
		valid: a.isUID(),
		different: a !== b,
		guid: GUID(20),
		sameHash: HASH('total') === HASH('total'),
		otherHash: HASH('total') !== HASH('Total'),
		type: typeof(HASH('total'))
	});
}
```
