Skip to content

Instantly share code, notes, and snippets.

@matdombrock
Last active August 29, 2015 14:08
Show Gist options
  • Save matdombrock/e3a22e58f0a97aecb606 to your computer and use it in GitHub Desktop.
Save matdombrock/e3a22e58f0a97aecb606 to your computer and use it in GitHub Desktop.
Generates a page with a link to a another random bitly page.
<div id="result">loading...</div>
<p id="reload">CLICK HERE TO GENERATE A NEW LINK</p>
<script>
function randomString(len, charSet) {
charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var randomString = '';
for (var i = 0; i < len; i++) {
var randomPoz = Math.floor(Math.random() * charSet.length);
randomString += charSet.substring(randomPoz,randomPoz+1);
}
return randomString;
}
function randomIntFromInterval(min,max) { return Math.floor(Math.random()*(max-min+1)+min); }
var randomValue = randomString(randomIntFromInterval(4,6));
$("#result").html("<a href='http://www.bit.ly/"+randomValue+"' target='_blank'>bit.ly/"+randomValue+"</a>");
$( "#reload" ).click(function() {
window.location.reload(true);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment