Skip to content

Instantly share code, notes, and snippets.

@Habush
Created September 8, 2019 14:44
Show Gist options
  • Save Habush/dee24386b918ecf01dd5031b2efb468e to your computer and use it in GitHub Desktop.
Save Habush/dee24386b918ecf01dd5031b2efb468e to your computer and use it in GitHub Desktop.
A simple scheme function to generate unique string ids
(use-modules (rnrs bytevectors))
(import (uuid))
(import (industria base64))
(define generate-id (lambda ()
(let* (
[vecs (bytevector->u8-list (random-uuid))]
[ls (let loop (
(i 0)
(ls '())
)
(if (= i 7)
ls
(loop (+ i 1) (cons (floor-remainder (list-ref vecs i) 64) ls))
)
)]
)
(list->string (let loop
(
(tmp ls)
(res '())
)
(if (null? tmp)
res
(loop (cdr tmp) (cons (string-ref base64url-alphabet (car tmp)) res)
)
)
)
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment