#!/usr/bin/python import random, time # Reference # http://stackoverflow.com/questions/3791400/how-can-you-select-a-random-element-from-a-list-and-have-it-be-removed # http://stackoverflow.com/questions/13890935/timestamp-python def random_pop(items): if items: random.shuffle(items) return items.pop() return None def random_string(slen=6): # Setup [pool]. This is the string the result will be taken from. pool_l = list("abcdefghijklmnopqrstuvwxyz") pool_u = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") pool_d = list("0123456789") pool = pool_l + pool_u + pool_d # Set the number of times [pool] will be shuffled seed = random.randint(1, 20) # Shuffle [pool] [random.shuffle(pool) for i in range(seed)] # Build the random string and convert to string res = "".join([random_pop(pool) for i in range(slen)]) return res def main(): print random_string(6) if __name__ == "__main__": main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question