Generate random integer


/ Published in: JavaScript
Save to your folder(s)

Usage:
random_integer(1,100);


Copy this code and paste it in your HTML
  1. /*
  2.   Receives the lowest and highest values of a range and
  3.   returns a random integer that falls within that range.
  4. */
  5. function random_integer(low, high)
  6. {
  7. return low + Math.floor(Math.random() * (high - low));
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.