Created
September 8, 2019 14:44
-
-
Save Habush/dee24386b918ecf01dd5031b2efb468e to your computer and use it in GitHub Desktop.
A simple scheme function to generate unique string ids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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