Skip to content

Instantly share code, notes, and snippets.

@NTT123
Created July 16, 2019 11:56
Show Gist options
  • Save NTT123/fed24276c88a9e91c3ab19831c307588 to your computer and use it in GitHub Desktop.
Save NTT123/fed24276c88a9e91c3ab19831c307588 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Universe Splitter</title>
</head>
<body>
<p>According to <a href="https://en.m.wikipedia.org/wiki/Many-worlds_interpretation">the many-worlds interpretation</a> of quantum mechanics, every possible outcome of a quantum experiment happens.</p>
<p>If your decision depends on the outcome of the experiment, there will be many versions of you who will make different decisions.
<p>By clicking the bellow button, you will receive a random binary number (0 or 1) from <a href="http://qrng.anu.edu.au/index.php">the ANU Quantum Random Numbers Server</a>.
There will be two versions of you, one will receive 0 and another will receive 1.</p>
<button id="splitter" type="button">Split the Universe</button>
<div id="app"></div>
<script>
function httpGet(theUrl)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
xmlHttp.send( null );
return xmlHttp.responseText;
}
document.getElementById("splitter").addEventListener("click", function(e){
let txt = httpGet("https://qrng.anu.edu.au/API/jsonI.php?length=1&type=uint8");
let obj = JSON.parse(txt);
let number = obj.data[0];
let appDiv = document.getElementById('app');
appDiv.innerHTML = `${number % 2} ${appDiv.innerHTML}`;
});
</script>
</body>
</html>
@NTT123
Copy link
Author

NTT123 commented Jul 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment