UUID Generator
Generate random UUID v4 identifiers in bulk. Copy individual UUIDs or all at once.
Developer
100% Free
Runs in Browser
Preview
GenerateUUIDs
d1936a0a-8336-4a8f-9621-788c5c0a7c4b2fd83eca-a9b6-4197-ba77-b994dbeb7161fad77881-f0d5-41b7-b743-0dbc760543f24c2769cf-ae6e-40de-93f5-bddc90c0ee67722682a2-c085-403b-b28c-b17fb730caa1Source Code
Toggle the controls below the code to live-edit the initial state values.
uuid-generator.tsx
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Badge } from "@/components/ui/badge";
import { Copy, Check, RefreshCw } from "lucide-react";
function generateUUID(): string {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
export default function UuidGenerator() {
const [count, setCount] = useState(5);
const [uuids, setUuids] = useState<string[]>(() =>
Array.from({ length: 5 }, generateUUID)
);
const [copied, setCopied] = useState(-1);
const [copiedAll, setCopiedAll] = useState(false);
const regenerate = () => {
setUuids(Array.from({ length: count }, generateUUID));
};
const copyOne = async (uuid: string, idx: number) => {
await navigator.clipboard.writeText(uuid);
setCopied(idx);
setTimeout(() => setCopied(-1), 1500);
};
const copyAll = async () => {
await navigator.clipboard.writeText(uuids.join("\n"));
setCopiedAll(true);
setTimeout(() => setCopiedAll(false), 1500);
};
return (
<div className="space-y-4">
<div className="flex flex-wrap items-center gap-3">
<span className="text-sm text-muted-foreground">Generate</span>
<Input
type="number"
min={1}
max={50}
value={count}
onChange={(e) => setCount(Number(e.target.value) || 1)}
className="w-20"
/>
<span className="text-sm text-muted-foreground">UUIDs</span>
<Button onClick={regenerate}>
<RefreshCw className="mr-2 h-4 w-4" />
Generate
</Button>
<Button variant="outline" onClick={copyAll}>
{copiedAll ? (
<Check className="mr-2 h-4 w-4" />
) : (
<Copy className="mr-2 h-4 w-4" />
)}
Copy All
</Button>
</div>
<div className="space-y-1">
{uuids.map((uuid, i) => (
<div
key={i}
className="flex items-center justify-between rounded-lg border px-3 py-2 hover:bg-muted/50 transition-colors"
>
<code className="text-sm font-mono">{uuid}</code>
<Button
variant="ghost"
size="icon"
className="h-7 w-7 shrink-0"
onClick={() => copyOne(uuid, i)}
>
{copied === i ? (
<Check className="h-3.5 w-3.5" />
) : (
<Copy className="h-3.5 w-3.5" />
)}
</Button>
</div>
))}
</div>
</div>
);
}
Props Playground
2 props
5
Boolean
Required Libraries
Install the external dependencies used by this tool.
bun add lucide-react react
Shadcn UI Setup
Add the required Shadcn UI primitives to your project.
bun x --bun shadcn@latest add badge button input
Shadcn UI Components
The following primitives are required in your
@/components/ui
directory.
| Component | Import Path |
|---|---|
| badge | @/components/ui/badge |
| button | @/components/ui/button |
| input | @/components/ui/input |
Imports
All import statements used in this tool.
| Source | Exports |
|---|---|
| react | useState |
| @/components/ui/button | Button |
| @/components/ui/input | Input |
| @/components/ui/badge | Badge |
| lucide-react | Copy, Check, RefreshCw |
State Management
React state variables managed within this tool.
| Variable | Initial Value |
|---|---|
| count | 5 |
| uuids | ( |
| copied | -1 |
| copiedAll | false |
Variables & Constants
Constants and computed values defined in this tool.
| Name | Value |
|---|---|
| v | c === "x" ? r : (r & 0x3) | 0x8 |
Functional Logic
Internal functions that handle the tool's core logic.
| Function | Parameters | Async |
|---|---|---|
| generateUUID() | None | No |
| regenerate() | None | No |
| copyOne() | uuid: string, idx: number |
Yes
|
| copyAll() | None |
Yes
|
External Resources
Documentation, tutorials, and package details for libraries used in this tool.