Advertisement
nher1625

js_math

May 28th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function randomPointOnCircle(radius) {
  2. // Pi or π is a mathematical constant equal to a
  3. // circle's circumference divided by its diameter.
  4.     var angle = Math.random() * 2 * Math.PI;
  5. // Math.random() 0 - 1 pseudorandom number in that range
  6.     return {x: radius * Math.cos(angle),
  7.             y: radius * Math.sin(angle)};
  8. }
  9. console.log(randomPointOnCircle(2));
  10.  
  11. function randomZeroToN(n) {
  12.     return Math.floor(Math.random() * n);
  13. }
  14. // Generate random number 0 - n
  15. var counter = 0;
  16. do {
  17.     console.log(randomZeroToN(100));
  18.     counter++;
  19. } while (counter < 10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement