import { unsafeStringify as e } from "./stringify.js";
import t from "./rng.js";
//#region ../../node_modules/uuid/dist/v4.js
function n(e, t, n) {
	return !t && !e && crypto.randomUUID ? crypto.randomUUID() : r(e, t, n);
}
function r(n, r, i) {
	n ||= {};
	let a = n.random ?? n.rng?.() ?? t();
	if (a.length < 16) throw Error("Random bytes length must be >= 16");
	if (a[6] = a[6] & 15 | 64, a[8] = a[8] & 63 | 128, r) {
		if (i ||= 0, i < 0 || i + 16 > r.length) throw RangeError(`UUID byte range ${i}:${i + 15} is out of buffer bounds`);
		for (let e = 0; e < 16; ++e) r[i + e] = a[e];
		return r;
	}
	return e(a);
}
//#endregion
export { n as default };

//# sourceMappingURL=v4.js.map