

// -----------------------------------------------------------------------------------------------------------------------------------------
/* DOCUMENT READY */

	function getDiceRoll () {
		
		return Math.floor(Math.random() * 6) + 1;
		
	}
	
	function addBox (num, list) {
	
		if (list == 'diceware') {
			var word = diceware[num];
		} else if (list == 'special') {
			var word = special[num];
		} 
		
		$('.new-diceword').append('<div class="new-diceword__box js__diceword-box"><div class="new-diceword__box-top">'+word+'</div><div class="new-diceword__box-bottom">'+num+'</div></div>');
		
	}
	
	// Ta!
	// http://www.drupalden.co.uk/get-values-from-url-query-string-jquery
	function getUrlVars() {
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++) {
		    hash = hashes[i].split('=');
		    vars.push(hash[0]);
		    vars[hash[0]] = hash[1];
		}
		return vars;
	}


	$(document).ready(function () {

		$('.js__new-word-button').on('click', function (e) {
		
			e.preventDefault();
			var num = '';
			for (i=0; i<5; i++) {
				
				num += getDiceRoll();
			}
			
			addBox (num, 'diceware');
			
		});
		
		$('.js__new-special-button').on('click', function (e) {
			
			e.preventDefault();
			var num = '';
			for (i=0; i<2; i++) {
				
				num += getDiceRoll();
			}
			
			addBox (num, 'special');

		});
		
		$('.js__new-lookup-input').keydown(function(event){    
			if(event.keyCode==13){
				$('.js__new-lookup-button').trigger('click');
			}
		});
		
		$('.js__new-lookup-button').on('click', function (e) {

			e.preventDefault();
			var buttonVal = $('.js__new-lookup-input').val();

			if ( (buttonVal).length != 5 && (buttonVal).length != 2 ) {
				
				$('.js__new-lookup-input').css('border-color', '#c00');
				
			} else {
				
				var proceed = true;
				for (var i = 0; i < (buttonVal).length; i++) {
				    if((buttonVal).charAt(i) < 1 || (buttonVal).charAt(i) > 6) {
					    
					    $('.js__new-lookup-input').css('border-color', '#c00');
					    proceed = false;
					    
				    }
				}
				
				if (proceed === true) {
					
					if ((buttonVal).length == 2) {
						
						addBox (buttonVal, 'special');
						$('.js__new-lookup-input').val('');
						
					} else {
					
						addBox (buttonVal, 'diceware');
						$('.js__new-lookup-input').val('');
					
					}
					
				}
				
			}

			var num = '';
			
		});
		
		$('.js__new-lookup-input').on('keyup', function() {
			
			$(this).css('border-color', '#333');
			
		});
		
		$('.new-diceword').on('click', '.js__diceword-box', function (e) {
		
			e.preventDefault();

			$(this).fadeOut('fast', function() {
				$(this).remove();
			});	
		});
		
		
		$('.list-title span').text(wordlist);
		

	});

@@ -163,88 +163,446 @@
 /%0A%0A%09
-function getDiceRoll () %7B%0A%09%09%0A%09%09return Math.floor(Math.random() *
+// Use a cryptographically strong random number generator%0A%09// to get the die roll results.%0A%09function getDiceRoll (numRolls) %7B%0A%09%09if (!numRolls) %7B numRolls = 5; %7D%0A%0A%09%09var array = new Uint32Array(numRolls);%0A%09%09window.crypto.getRandomValues(array);%0A%0A%09%09var rollResults = %5B%5D;%0A%09%09for (var i = 0; i %3C array.length; i++) %7B%0A%09%09%09// Convert random Byte into 6 sided die roll%0A%09%09%09rollResults.push((array%5Bi%5D %25
  6) + 1
+)
 ;%0A%09%09
+%7D%0A%09%09return rollResults.join('');
 %0A%09%7D%0A
-%09
 %0A%09fu
@@ -1454,101 +1454,30 @@
 %0A%09%09%09
-var num = '';%0A%09%09%09for (i=0; i%3C5; i++) %7B%0A%09%09%09%09%0A%09%09%09%09num += getDiceRoll();%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09addBox (num
+addBox (getDiceRoll(5)
 , 'd
@@ -1483,27 +1483,24 @@
 diceware');%0A
-%09%09%09
 %0A%09%09%7D);%0A%09%09%0A%09%09
@@ -1589,101 +1589,30 @@
 %0A%09%09%09
-var num = '';%0A%09%09%09for (i=0; i%3C2; i++) %7B%0A%09%09%09%09%0A%09%09%09%09num += getDiceRoll();%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09addBox (num
+addBox (getDiceRoll(2)
 , 's

Use window.crypto.getRandomValues(), a CSPRNG