function*distinctRandom({limit=10}){// we create an array that contains all numbers in range [0:limit)// this is our initial pool of numbers to choose fromconstavailableValues=[...newArray(limit).keys()];// we repeatedly loop until the available pool of numbers is emptywhile(availableValues.length!==0){// generate a random index in range [0: availableValues.length)// then, yield the number that is present at the chosen index// Finally, remove the picked item from the pool of available numbersconstcurrentRandom=Math.floor(Math.random()*availableValues.length);yieldavailableValues.splice(currentRandom,1)[0];}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Better distinctRandom: