Exchange of values

This page is about the exchange of values and making a program that shuffles.

// Warning! This code may be inaccurate in syntax or may not work properly.
// Please refrain from using it.
 
function exchangethese(a,b) {
var c=a;
a=b;
b=c;
}
//Practical use:
function randomswapthese() {
var a=prompt("What's the first thing?");
var b=prompt("What's the second thing?");
var r=Math.random();
while (r<0.5) {
var c=a;
a=b;
b=c;
r=Math.random(); //code is not supposed to be infinite.
}
}
//Also a shuffler
function shufflethese(numbertoswap) {
if (isNaN(number to swap)) {
alert("Error. Argument is not a number.")
}
else {
var myDeckToShuffle = new Array();
while(numbertoswap>0) {
myDeckToShuffle[numbertoswap]=prompt("Enter a string.");
numbertoswap--;
}
contswapping=Math.random();
while (contswapping<(1 - Math.pow(1 / numbertoswap , 10));) {
firstran = ceil(Math.random()*numbertoswap);
while (secondran!=firstran) {
secondran = ceil(Math.random()*numbertoswap);
}
emptytemp = myDeckToShuffle[firstran];
myDeckToShuffle[firstran] = myDeckToShuffle[secondran];
myDeckToShuffle[secondran] = emptytemp;
contswapping=Math.random();
} //shuffler ends
} // else code ends
} // function ends
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License