dimanche 28 juin 2015

JS: How to create a random picker that won't pick the same item twice?

I'm making a random hero picker for a game, and this tool will randomly pick heroes for the player. I want to add a feature where it picks the heroes for the whole team of 3, but I don't know how to make it so that the same hero won't be pick more than once. Here is a sample of my code for picking a random hero for a player. Thank you in advance!!!!

<script language="JavaScript">

function pickhero(){
var imagenumber = 16 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1;
images = new Array
images[1] = "http://ift.tt/1TZeYSO"
images[2] = "http://ift.tt/1Ns7PW7"
images[3] = "http://ift.tt/1TZeYSQ"
images[4] = "http://ift.tt/1Ns7PW9"
images[5] = "http://ift.tt/1Ns7Ol0"
images[6] = "http://ift.tt/1TZeYSW"
images[7] = "http://ift.tt/1Ns7Qcp"
images[8] = "http://ift.tt/1TZeYT0"
images[9] = "http://ift.tt/1Ns7Qcr"
images[10] = "http://ift.tt/1TZeZ9g"
images[11] = "http://ift.tt/1Ns7Qct"
images[12] = "http://ift.tt/1TZeZ9i"
images[13] = "http://ift.tt/1Ns7Ol2"
images[14] = "http://ift.tt/1TZeXOP"
images[15] = "http://ift.tt/1TZeZ9k"
images[16] = "http://ift.tt/1Ns7Ol4"
var image = images[rand1]
document.team1hero1.src = image
}
</script>




Aucun commentaire:

Enregistrer un commentaire