|
[Python] Function for random String
|
|
02-12-2010, 08:13 AM
(This post was last modified: 02-12-2010 08:23 AM by Alphablend.)
Post: #1
|
|||
|
|||
|
[Python] Function for random String
You call the function entering any length of string that you wish.
Code: def randstring(k):You will probably get the result like this one: Code: >>> randstring(100)You can go a step further and change the probability of getting the desired size of letters. Lets say we want our function to random upper case letters with twice bigger chance than lower case letters. This is one nice way how to do it. You just have to change one tiny little thing in the code. I will just copy the line that you have to change. Code: BS_letter=randint(0,2) |
|||
|
02-12-2010, 11:55 AM
(This post was last modified: 02-12-2010 11:57 AM by codecaine.)
Post: #2
|
|||
|
|||
|
RE: [Python] Function for random String
Nice work this is how I did it. The string modules already have constant string etc you can use.
Code: from string import letters; |
|||
|
02-12-2010, 10:15 PM
Post: #3
|
|||
|
|||
|
RE: [Python] Function for random String
Very good. This is like some kind of random password generator. I made one in JavaScript :
http://www.pro9ramming.com/random-passwo...t-767.html You could make that it asks you if you want to enter small letters or numbers or signs of Punctuation. Very good work though ! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
02-13-2010, 12:08 AM
(This post was last modified: 02-13-2010 02:32 AM by Alphablend.)
Post: #4
|
|||
|
|||
|
RE: [Python] Function for random String
Thanks codecaine.
I did this like a classic Java programmer. Lol. I still don't know some benefits of Python. I imported random and checked all functions with 'help(random)', but didn't "catch" this one. Actually I did have this task in Java. And decided to write it in Python. |
|||
|
03-11-2010, 07:46 AM
Post: #5
|
|||
|
|||
RE: [Python] Function for random String
(02-13-2010 12:08 AM)Alphablend Wrote: Thanks codecaine. Anytime
|
|||
|
« Next Oldest | Next Newest »
|






