generate an array of random numbers javascript
var arr = [];
while(arr.length < 8){
var r = Math.floor(Math.random() * 100) + 1;
if(arr.indexOf(r) === -1) arr.push(r);
}
console.log(arr);//This example is to generate an array with 40 random elements, with random values from 0 to 39
for (var a=[],i=0;i<40;++i) a[i]=i;
// http://stackoverflow.com/questions/962802#962890
function shuffle(array) {
var tmp, current, top = array.length;
if(top) while(--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
return array;
}
a = shuffle(a);
let numbersArray = [] , max = 100;
for( var i=1; numbersArray.push(i++) < max;); // numbers = [1,2,3 ... 100]
Also in JavaScript:
- close current tab javascript
- get all entries in object as array hjs
- js user add names to a list on screen
- how to use a fixed time zone in nodejs
- get today's date javascript
- vuetify event handler
- html shortcuts in jsx
- react router dom npm
- jquery get value of td by class
- how to submit a form in js
- date difference
- ad data to js object
- jest axios manual mock
- trigger button click jquery
- fetch js
- jquery select self and siblings
- react replace all line breaks with br
- Returning Boolean Values from Functions
- how to debug node js file in webpack
- edit json via nodejs
- post json in flutter
- data table in angular 8 from api
- how to move an ellipse along the x axis in javascript
- python json.dumps pretty print