Add "Generate random number" on bottom of patcher

This commit is contained in:
Michal Moskal 2019-06-22 20:32:43 -07:00
parent 1961540772
commit 6e8bab5245
2 changed files with 13 additions and 0 deletions

View file

@ -59,6 +59,11 @@
<a href="#" onclick="defines()">download configkeys.h</a>.
</p>
<p>
<a href="#" id="rnd">Generate random number</a>
<span id="rnd-res"></span>
</p>
<footer>
<a href="https://makecode.com/privacy" target="_blank" rel="noopener">Privacy &amp; Cookies</a>

View file

@ -5,10 +5,18 @@ function savePatch(ev) {
localStorage["UF2_PATCH"] = text.value
}
function genRnd() {
let vals = new Uint32Array(1)
window.crypto.getRandomValues(vals)
document.getElementById("rnd-res").textContent = "Random number: 0x" +
("000000000" + vals[0].toString(16)).slice(-8)
}
function restorePatch() {
let text = document.getElementById("patch")
text.value = localStorage["UF2_PATCH"] || ""
document.getElementById("apply").onclick = applyPatch
document.getElementById("rnd").onclick = genRnd
}
function download(buf, name) {