stuppid_bot

Random

Dec 17th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  *
  3.  * Random
  4.  *
  5.  **/
  6. function rand(min, max)
  7. {
  8.     return Math.random() * (max - min + 1) + min;  
  9. }
  10.  
  11. function randInt(min, max)
  12. {
  13.     return Math.floor(rand(min, max));
  14. }
  15.  
  16. function randElem(arr)
  17. {
  18.     return arr[randInt(0, arr.length - 1)];
  19. }
  20.  
  21. function randStr(len, chars)
  22. {
  23.     if (len == undefined)  {
  24.         len = 8;
  25.     }
  26.     if (chars == undefined) {
  27.         chars = '1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm';
  28.     }
  29.     var out = '';
  30.     for (var i = 0; i < len; ++i) {
  31.         out += randElem(chars);
  32.     }
  33.     return out;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment