import { unsafeStringify } from "./stringify.js";
import rng from "./rng.js";
import native_default from "./native.js";
function v4(r, i, a) {
	if (native_default.randomUUID && !i && !r) return native_default.randomUUID();
	r ||= {};
	let o = r.random ?? r.rng?.() ?? rng();
	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 unsafeStringify(o);
}
var v4_default = v4;
export { v4_default as default };
