You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RandomUtil.js 868B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Generates random hex number within the range [min, max]
  3. * @param max the maximum value for the generated number
  4. * @param min the minimum value for the generated number
  5. * @returns random hex number
  6. */
  7. function rangeRandomHex(min, max)
  8. {
  9. return Math.floor(Math.random() * (max - min) + min).toString(16);
  10. }
  11. /**
  12. * Exported interface.
  13. */
  14. var RandomUtil = {
  15. /**
  16. * Generates hex number with length 4
  17. */
  18. random4digitsHex: function() {
  19. return rangeRandomHex(4096, 65535);
  20. },
  21. /**
  22. * Generates hex number with length 8
  23. */
  24. random8digitsHex: function() {
  25. return rangeRandomHex(268435456, 4294967295);
  26. },
  27. /**
  28. * Generates hex number with length 12
  29. */
  30. random12digitsHex: function() {
  31. return rangeRandomHex(17592186044416, 281474976710655);
  32. }
  33. };
  34. module.exports = RandomUtil;