Hello Haskellers,
I want to make a QuickCheck generator that creates identifiers, basically
[a-zA-Z] as the first character and then [a-zA-Z0-9-_] for a total of 63
characters. So, I've got up to:
do s <- choose (1, 63 :: Int)
elements validFirstChars
where validFirstChars = ['a'..'z'] ++ ['A'..'Z']
validChars = validFirstChars ++ "_-" ++ ['0'..'9']
which of course only gives me one random character. I want both, the
characters, and the length to be random.
Thank you.
--
J. Pablo Fernández
On Tuesday 24 July 2007, J. Pablo Fernández wrote:
Hello Haskellers,
I want to make a QuickCheck generator that creates identifiers, basically [a-zA-Z] as the first character and then [a-zA-Z0-9-_] for a total of 63 characters. So, I've got up to:
do s <- choose (1, 63 :: Int) elements validFirstChars where validFirstChars = ['a'..'z'] ++ ['A'..'Z'] validChars = validFirstChars ++ "_-" ++ ['0'..'9']
which of course only gives me one random character. I want both, the characters, and the length to be random.
do n <- choose (1, 63) replicateM $ elements validFirstChars Jonathan Cast http://sourceforge.net/projects/fid-core http://sourceforge.net/projects/fid-emacs
Thank you Jonathan for your answer, it really helped me find the solution, which, just for the record, was: correctLabelGenerator = do s <- choose (1, 63 :: Int) liftM2 (:) (elements validFirstChars) (replicateM (s - 1) (elements validChars)) where validFirstChars = ['a'..'z'] ++ ['A'..'Z'] validChars = validFirstChars ++ "_-" ++ ['0'..'9'] Thank you. On Tuesday 24 July 2007 14:55:33 Jonathan Cast wrote:
On Tuesday 24 July 2007, J. Pablo Fernández wrote:
Hello Haskellers,
I want to make a QuickCheck generator that creates identifiers, basically [a-zA-Z] as the first character and then [a-zA-Z0-9-_] for a total of 63 characters. So, I've got up to:
do s <- choose (1, 63 :: Int) elements validFirstChars where validFirstChars = ['a'..'z'] ++ ['A'..'Z'] validChars = validFirstChars ++ "_-" ++ ['0'..'9']
which of course only gives me one random character. I want both, the characters, and the length to be random.
do n <- choose (1, 63) replicateM $ elements validFirstChars
Jonathan Cast http://sourceforge.net/projects/fid-core http://sourceforge.net/projects/fid-emacs _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
--
J. Pablo Fernández
participants (2)
-
J. Pablo Fernández -
Jonathan Cast