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