#lang racket/base
;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2019-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>

(provide strong-gensym)

(require (only-in net/base64 base64-encode))
(require (only-in racket/random crypto-random-bytes))
(require (only-in racket/string string-trim))

(define (strong-gensym [head 'g] #:random-bytes [count 16])
  (string->symbol
   (format "~a~a"
           head
           (string-trim (bytes->string/latin-1
                         (base64-encode (crypto-random-bytes count) #""))
                        #px"=+"))))
