Randomizing Demonstration of the Euclidean Algorithm for Infinite Quantity of Integers.
This does not perform GCD seperately -- on all pairs of integers in a set of two or more integers, but sorts and performs GCD on neighboring pairs resulting from a presort, and then integrates all remainders by resorting them before repeating the GCD upon neighboring remainders which have not yet zeroed out. The smallest integer, or remainder, is always GCD'ed with zero to obtain a remainder equal to itself to ensure a quantity of modulo operations equal to the quantity of terms (rather than a quantity of modulo operations one less than the full quantity of non-zeroed terms).
by Vinyasi
HTML
<div align="center">
<span id="demonstration"></span>
</div>
JavaScript
/*
Written by Vinyasi in 2016, copyleft.
*/
function gcd_randomizing_demo(count, limit) {
// 'count' is the maximum quantity of random numbers
// 'limit' is the maximum size of each multiplier
var text = ''; // is returned to the function call
text += '<table class="chart" border="3" cellpadding="4" cellspacing="15">' + "\n";
text += '<caption><b>' + "\n";
text += 'The Euclidean Algorithm' + "\n";
text += '</b></caption>' + "\n";
text += '<tr style="background-color: #ffeecc"><th>' + "\n";
// Alter these four values if you like...
var min = 10; // minimum size of random number seeds
var size = 500; // size limit of random number seeds
var limb = 1; // multiplier minimum size
var kows = 1; // is the maximum quantity of multipliers
var x;
var i;
var v;
var w;
var mult = 1; // preinitialize the composite multiplier
// This has to be at least one greater than the largest possible random number.
// Otherwise, the sort function will push all the numbers to the
// top of the terms array and begin to cut them out a little at a time!
var numeric_padding = (size * Math.pow(limit, kows)) + 1;
var cows = Math.floor((Math.random() * (kows - 1)) + 1); // actual quantity of multipliers
var multiplier = [];
for (x = 0; x < cows; x++) {
multiplier[x] = Math.floor((Math.random() * (limit - 1)) + limb);
mult = mult * multiplier[x];
}
var cownt = Math.floor((Math.random() * (count - 1)) + 2); // actual quantity of random numbers
var save_cownt = cownt;
text += cownt + ' random numbers';
var terms = [];
var booboo;
var color_orange;
for (i = 0; i < cownt; i++) {
terms[i] = Math.floor((Math.random() * (size - 1)) + min);
for (w = 0; w < i; w++) // test for duplicate random numbers and try again if true
{
if (terms[i] == terms[w]) {
booboo = true;
i--;
break;
}
}
if (i % 2 === 0) {
color_orange = 'ffd5a2';
} else {
...