uuid.ts 499 B

123456789101112131415161718
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. /**
  4. * Get a random hex string (not a formal UUID).
  5. *
  6. * @param length - The length of the hex string.
  7. */
  8. export
  9. function uuid(length: number=32): string {
  10. let s = new Array<string>(length);
  11. let hexDigits = '0123456789abcdef';
  12. let nChars = hexDigits.length;
  13. for (let i = 0; i < length; i++) {
  14. s[i] = hexDigits.charAt(Math.floor(Math.random() * nChars));
  15. }
  16. return s.join('');
  17. }