Random Data Generator (Bytes/Strings)

Random Data Generator (Bytes/Strings)

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.

Parameters Used:

  • Output Type: ${rdg_lastType}
  • Bytes Generated: ${rdg_lastLength} bytes

Generated Data Output:

${rdg_escapeHTML(rdg_lastOutput)}

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)); } }); });
Scroll to Top