Skip to content

Commit

Permalink
customNanoID rewritten
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelBoucey committed Jun 8, 2023
1 parent da31b4d commit dbd1d1c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Data/NanoID.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbd1d1c

Please sign in to comment.