Advertisement
BaSs_HaXoR

Python 1 Line Random String

Aug 14th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #Credits: LOLDONGS : http://pastebin.com/u/loldongs
  2. Here is a very simple, 1 line function, to return a random string of characters, of any given length you specify.
  3.  
  4. ##################################################
  5.  
  6. #IMPORTS
  7. import random
  8.  
  9. #GET RANDOM
  10. def getRandom(length): return ''.join(random.sample('abcdefghijklmnopqrstuvwxyz', length))
  11.  
  12. ##################################################
  13.  
  14. You would call this by using an integer for the "length" argument. For example :
  15.  
  16. variable = getRandom(20)
  17. print(variable)
  18. 'uedxkcygka'
  19.  
  20.  
  21.  
  22. NOTE: This only returns a random string using lowercase letters. You can easily modify it to use whatever characters you want.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement