0

I asked this question 2nd time because 1st time someone closed my question and I didn't get 1 satisfactory answer. Please read my question carefully

i am trying to create an array where random elements do not overlap when i load the page for the first time, but it crashes what should i do?

first i want to generate random number from 1-10....but how to generate this if i want to change from 1-20 and take only 10 non-matching numbers? my random numbers may vary in random range, not fixed from 1-10, take a look at my code above

I don't intend to randomly ask for a number from a given array

  $(window).on('load', function () {
            const a = [];
           
            for(let i = 0; a.length < 10;){
                let b = Math.floor(Math.random() * 10) + 1;
                if(a.indexOf(b) === -1){
                    a.push(b);

                }
            }
        })

what I want above when I change C to 20, it will be random 1-20, C= 30=> random 1-30

0 Answers0