Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const numbers = [75, -18, 216, 21, -6, 352, 39, -68, -318, 182];
- //const var seed = 42 JS doesn't support seeded rng
- function nonrand(i){
- return numbers[i];
- }
- // print random int from -999 through 999
- function random(){
- return Math.floor(Math.random() * 999);
- }
- function mean(a){
- var avg = 0;
- for(var i = 0; i < a.length; i++)
- avg += a[i];
- return avg / a.length;
- }
- var x = []
- var y = []
- for(var i = 0; i < 10; i++){
- x.push(nonrand(i));
- y.push(random());
- }
- x.sort(function(a, b) {return a-b});
- y.sort(function(a, b) {return a-b});
- console.log('\tNONRAND\tRAND');
- console.log('MIN\t', x[0], '\t', y[0])
- console.log('MAX\t', x[9], '\t', y[9])
- console.log('MEAN\t', mean(x), '\t', mean(y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement