From dbd1d1cbed2676b3fe9d21a5d0421e321ed70a46 Mon Sep 17 00:00:00 2001 From: Michel Boucey Date: Thu, 8 Jun 2023 19:49:40 +0200 Subject: [PATCH] customNanoID rewritten --- lib/Data/NanoID.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Data/NanoID.hs b/lib/Data/NanoID.hs index 0cf98f6..9211ed3 100644 --- a/lib/Data/NanoID.hs +++ b/lib/Data/NanoID.hs @@ -61,10 +61,12 @@ customNanoID :: Alphabet -- ^ An 'Alphabet' of your choice -> GenIO -- ^ The pseudo-random number generator state -> IO NanoID customNanoID a l g = - NanoID . C.pack <$> replicateM (fromEnum l) ((\r -> C.index ua (r-1)) <$> uniformR (1,al) g) - where + let ua = unAlphabet a al = C.length ua + l' = fromEnum l + in + NanoID . C.pack <$> replicateM l' ((\r -> C.index ua (r-1)) <$> uniformR (1,al) g) -- | The default 'Alphabet', made of URL-friendly symbols. defaultAlphabet :: Alphabet