joefromsansnite

Untitled

Nov 11th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. local UUIDGenerator = {}
  2.  
  3. function UUIDGenerator:Generate(dashes: boolean?)
  4. dashes = (type(dashes) ~= "boolean") and true or dashes
  5.  
  6. local uuid = ""
  7. local length = 32
  8.  
  9. for i = 1, length/4 do
  10. for i_ = 1, math.random(2, 4) do
  11. local hex = math.random(0, 255)
  12. hex = ("%x"):format(hex)
  13.  
  14. uuid = uuid..hex
  15. end
  16. if dashes then
  17. if i == length/4 then
  18. continue
  19. end
  20. uuid = uuid.."-"
  21. end
  22. end
  23.  
  24. return uuid:sub(1, length)
  25. end
  26.  
  27. return UUIDGenerator
Advertisement
Add Comment
Please, Sign In to add comment