vendredi 8 avril 2016

math.rand if inArray new math.rand

I have this part of my function that generates a rand number. After generating the number it checks to see if its in an array. If not the function continues and in the end adds the random number to the array to check for in the next loop. Im messing up on creating a new random number if its found in the said array. I tried new random which is the name of the variable but got error saying its not a constructor. How can i complete this loop?

            explode: function () {
            var input = this.input,
                    bomb = input.split("\n\n"),
                    bomb_size = bomb.length,
                    striked = [], // this is the array where the numbers will be stored.
                    small_portion = bomb_size * .25;
            for (var i = 0; i < small_portion; i++) {
                var random = Math.floor(Math.random()*(bomb_size-0+1)+0), // generating random number with paramaters not to excced bomb size
                        isStriked = $.inArray(random, striked);

                if(isStriked < 0){
                    random = Math.floor(Math.random()*(bomb_size-0+1)+0);
                    console.log(random + ' the new one'); // where the new number should be made if found in striked array. 
                }
                bomb[random] = '~~'+bomb[i]+'~~'
                striked.push(random);
            }
            console.log(striked);
            var group = bomb.join("\n\n");

            this.input = group;
        }
    },




Aucun commentaire:

Enregistrer un commentaire