c++ - Alphanumeric generator with restrictions -
i want create generator use these characters: b c d f g h j k m p q r t v w x y z 2 3 4 6 7 8 9
i want select 18 random letters list , 7 random numbers list , shuffle them (total of 25). there can repeats. python or c++. please help!
python code attempt:
import string import random letters = [random.choice('bcdfghjkmpqrtvwxyz') x in range(18)] numbers = [random.choice('2346789') x in range(7)] random.shuffle(letters + numbers)
you had right:
>>> import random >>> letters = [random.choice('bcdfghjkmpqrtvwxyz') x in range(18)] >>> numbers = [random.choice('2346789') x in range(7)] >>> s = letters + numbers >>> random.shuffle(s) >>> s ['j', 'p', 'f', 'm', '3', 'q', 'k', 'p', '2', 'k', '7', 'j', 'b', 'p', 'x', 'g', 'm', 'b', 'k', '9', '9', 'b', '8', 'v', '8']
random.shuffle(letters+numbers)
works, sort of, shuffle
works in-place , returns none
. you're creating temporary list, shuffling it, , losing reference it.
btw, if needed:
>>> ''.join(s) 'jpfm3qkp2k7jbpxgmbk99b8v8'
Comments
Post a Comment