Advertisement
electricmaster

Assignment4.js

Dec 2nd, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const numbers = [75, -18, 216, 21, -6, 352, 39, -68, -318, 182];
  2. //const var seed = 42 JS doesn't support seeded rng
  3.  
  4. function nonrand(i){
  5.     return numbers[i];
  6. }
  7.  
  8. // print random int from -999 through 999
  9. function random(){
  10.     return Math.floor(Math.random() * 999);
  11. }
  12.  
  13. function mean(a){
  14.     var avg = 0;
  15.     for(var i = 0; i < a.length; i++)
  16.         avg += a[i];
  17.     return avg / a.length;
  18. }
  19.  
  20. var x = []
  21. var y = []
  22.  
  23. for(var i = 0; i < 10; i++){
  24.     x.push(nonrand(i));
  25.     y.push(random());
  26. }
  27. x.sort(function(a, b) {return a-b});
  28. y.sort(function(a, b) {return a-b});
  29.  
  30. console.log('\tNONRAND\tRAND');
  31. console.log('MIN\t', x[0], '\t', y[0])
  32. console.log('MAX\t', x[9], '\t', y[9])
  33. console.log('MEAN\t', mean(x), '\t', mean(y))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement