Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h3>Dice Online Verifier</h3>	
<div id="container" class="container">
	<div id="form" class="block">
		
		<div class="field">
			<label for="server_seed">Server seed</label>
			<input id="server_seed" type="text" class="form_text"/>
		</div>
		
		<div class="field">
			<label for="client_seed">Client seed</label>
			<input id="client_seed" type="text" class="form_text"/>
		</div>
		
		<div class="field">
			<label for="nonce">Nonce</label>
			<input id="nonce" type="text" class="form_text"/>
		</div>
		
		<div class="field">
			<label for="hash">Server seed SHA512</label>
			<textarea id="hash" type="text" class="form_text" disabled></textarea>
		</div>
		
	</div>
	
	<div class="block">
		<label for="resultPanel">Result</label>
		<div id="resultPanel" class="resultPanel"></div>
	</div>	
	
</div>
              
            
!

CSS

              
                body {
	font-family: "Roboto Mono", monospace !important;
	min-width: 320px;
	box-sizing: border-box;
	padding: 10px;
	h3 {
		margin-left: 2.5px;
	}
	.container {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		box-sizing: border-box;
		.block {
			flex: 1;
			min-width: 250px;
			margin: 0 2.5px;
			box-sizing: border-box;
			label {
				font-weight: bold;
				font-size: 20px;
				box-sizing: border-box;
			}
			.field {
				display: flex;
				flex-direction: column;
				box-sizing: border-box;
				margin-bottom: 5px;
				textarea,
				input {
					font-size: 13px;
					padding: 5px;
					width: 100%;
					border-radius: 5px;
					border: 1px solid #888888;
					box-sizing: border-box;
					background-color: #ffffe1;
				}
				textarea {
					resize: none;
					height: 80px;
				}
				.configDescription {
					display: inline-block;
					font-size: 15px;
				}
			}
		}
	}
}

.c {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 30px;
	width: 100px;
	height: 48px;
	border-radius: 10px;
	border: 4px solid #333;
	background-color: lightgrey;
}
              
            
!

JS

              
                const params = {
	server_seed:"",
	client_seed:"",
	nonce:""
};

const roll = (serverSeed, clientSeed, nonce) => {
	const keyString = clientSeed + "-" + nonce;
	const hash = sha512.hmac(serverSeed, keyString);
	const random = parseInt(hash.substring(0, 5), 16) / 1048576;
	//from min - under max values
	const max = 10000;	
	return Math.floor(random * max);	
};

function showRandomResult(random){		
	$("#hash").val(sha512.hmac(params.server_seed, ''));
	let str = "" + random;
	while(str.length < 4) str="0" + str;
	str = `${str.substr(0,2)}.${str.substr(2)}`;
	$("#resultPanel").html(`<div class='c'><b>${str}</b></div>`);		
}

const calculateResult = () => {	
	for(let k in params) params[k] = $("#" + k).val().trim();
	$("#hash").val(sha512(params.server_seed));
	
	let random = roll(params.server_seed, params.client_seed, params.nonce);
	showRandomResult(random);
}

window.onload = function(){
	try{
		let url_string = (window.location.href);
		let url = new URL(url_string);		
		for(let k in params) {
			let value = url.searchParams.get(k);
			if(value){
				value = atob(value).trim();
				params[k] = value;
				$("#" + k).val(value);
			}
		}
		calculateResult();
	}
	catch{}
}

$('#form').keyup(()=>calculateResult());





              
            
!
999px

Console