Created
March 27, 2012 00:09
-
-
Save jdpaton/2210886 to your computer and use it in GitHub Desktop.
Generate a random lowercase string with at least one number
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
python -c "import random; x = [random.choice('23456789') for x in range(1)] + [ random.choice('abcdefghjkmnpqrstwxyz') for x in range(3)]; random.shuffle(x); print ''.join(x)" |
chr 50 == 2 + [0..7](rand 8). I don't know that we need full readability on this, and the no-external modules perl solution seems fine as it fills all the criteria, even randomizing the digit. I need 1..4 to get 4 chars though. Jan - is that a buglet?
@jeff-hobbs: Yes, my latest entry should have 1..4 in it. And dropping the 'u' saves another character:
perl -e'@_=map substr(abcdefghjkmnpqrstwxyz,rand 21,1),1..4;splice@_,rand@_,1,chr 50+rand 8;print @_'
Finally, I would like to change @_ to @$ as a hidden reference to ActiveState (@$ is ActiveState similar to how *$ is Starbucks):
perl -e'@$=map substr(abcdefghjkmnpqrstwxyz,rand 21,1),1..4;splice@$,rand@$,1,chr 50+rand 8;print @$'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I still need to figure out how to only generate one number and randomise it's position....
(Note the 'u' is gone too, forgot to mention that character can be dropped)
Jan, it's not easy to see how you are not generating the numeric zero / 1, are you starting the numeric index from > 1? I'm intrigued :)