Random Data Generator (Bytes/Strings)
Configure the output format and length, then generate a cryptographically secure random sequence for use in testing or application development.
Parameters
Generated Output
Click 'Generate Data' to create a random sequence.
Output Type Definitions
This section explains the different encoding formats available for the random bytes generated.
Hexadecimal String
A **Hexadecimal (Hex)** string represents raw binary data as two alphanumeric characters per byte (e.g., `a3` represents the byte `10100011`). It is commonly used for displaying machine data because it is concise and easy to debug. The resulting string length is exactly double the byte length requested.
Base64 String
A **Base64** string represents binary data using only ASCII characters (A-Z, a-z, 0-9, +, /, and = padding). This is ideal for transmitting binary data across mediums that only handle text, like URLs or JSON. It typically requires about 33% more space than the original bytes.
Raw Byte Array
This represents the **raw binary data** generated by the cryptographic engine. When displayed, it is converted to a Hex string for human readability, but conceptually it refers to the underlying binary sequence (e.g., used for cryptographic keys or salts).
Note: This is the last sequence generated by the browser's cryptographic API.
`; } /** * Generates and downloads a PDF of the output */ async function rdg_downloadPDF() { if (rdg_lastOutput === "N/A") { alert("Please generate data first before downloading."); return; } if (typeof jspdf === 'undefined' || typeof html2canvas === 'undefined') { alert("Error: PDF libraries failed to load."); return; } rdg_renderPdfClone(); const { jsPDF } = window.jspdf; try { const canvas = await html2canvas(rdg_pdfRenderClone, { scale: 1.5, useCORS: true }); const imgData = canvas.toDataURL('image/png'); const imgProps = { width: canvas.width, height: canvas.height }; const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const margin = 40; const contentWidth = pdfWidth - (margin * 2); const contentHeight = (contentWidth * imgProps.height) / imgProps.width; let heightLeft = contentHeight; let position = 0; pdf.addImage(imgData, 'PNG', margin, position + margin, contentWidth, contentHeight); heightLeft -= (pdfHeight - margin * 2); while (heightLeft > 0) { position -= (pdfHeight - margin * 2); pdf.addPage(); pdf.addImage(imgData, 'PNG', margin, position + margin, contentWidth, contentHeight); heightLeft -= (pdfHeight - margin * 2); } const safeName = (rdg_lastType || 'random_data').replace(/[^a-z0-9]/gi, '_').toLowerCase(); pdf.save(`${safeName}_${rdg_lastLength}B.pdf`); } catch (error) { console.error("PDF generation failed:", error); alert("An error occurred while generating the PDF."); } } // --- EVENT LISTENERS --- // Tab link clicks rdg_tabLinks.forEach((link, index) => { link.addEventListener('click', () => rdg_switchTab(index)); }); // Next/Prev button clicks if (rdg_prevButton) { rdg_prevButton.addEventListener('click', () => { if (rdg_currentTab > 0) rdg_switchTab(rdg_currentTab - 1); }); } if (rdg_nextButton) { rdg_nextButton.addEventListener('click', () => { const targetIndex = rdg_currentTab === 0 ? 1 : 0; rdg_switchTab(targetIndex); }); } // PDF download if (rdg_downloadPdfButton) { rdg_downloadPdfButton.addEventListener('click', rdg_downloadPDF); } // Generation controls if (rdg_generateButton) { rdg_generateButton.addEventListener('click', rdg_generate); } if (rdg_copyButton) { rdg_copyButton.addEventListener('click', rdg_copyToClipboard); } // --- INITIALIZATION --- // Pre-generate initial data based on defaults rdg_generate(); // Set initial tab state rdg_tabPanes.forEach((pane, index) => { pane.classList.toggle('hidden', index !== 0); pane.classList.toggle('rdg-active', index === 0); }); rdg_tabLinks.forEach((link, index) => { TAB_CLASSES.active.forEach(cls => link.classList.remove(cls)); TAB_CLASSES.inactive.forEach(cls => link.classList.remove(cls)); if (index === 0) { TAB_CLASSES.active.forEach(cls => link.classList.add(cls)); } else { TAB_CLASSES.inactive.forEach(cls => link.classList.add(cls)); } }); });