+ 1

How to avoid Consecutive Lowercase or Uppercase Letters in a random execution?

I wrote a code, for example: import random c = 'ABCDabcd1234' rand = '' for i in range(10): rand += random.choice(d) print (rand) How to Avoid Consecutive Lowercase or Uppercase or numbers here? I tried many times!!! Above code is just a simple one to understand my request. I do NOT want this result on my Terminal: qAd1f41234 : IT HAS 4 Consecutive numbers. qrtJFJ123 : IT HAS 3 Consecutive Lowercase and Upper and numbers. HOW TO AVOID THIS? how to avoid Consecutive things??

20th Oct 2019, 3:02 PM
Daniel Amini
Daniel Amini - avatar
13 Respuestas
+ 2
Hello Miika! as you said "make sure the next index is not the same as lastIndex." I couldn't do that! here is my code... : import random #This is our LIST include our chars... src = [ "ABCDE", "abcde", "12345", "@#$%&" ] password = '' count = 0 while count < 10: #for _ in range(1): password += random.choice(src[random.randint(0,3)]) count += 1 print(password) >>>CBE2de1Be5 Now we almost done!!! but how to make sure the next index is not same as previous one?!
22nd Oct 2019, 2:48 PM
Daniel Amini
Daniel Amini - avatar
+ 1
Your question is really weird, how is this any beneficial ? And what are you going to use it in anyway ?
20th Oct 2019, 3:23 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
hi Aymane, I need to know how "www.passwordmeter.com" calculates consecutive characters. This site gives negative point to Consecutive characters! I want generate a password without any negative point! ok? ;) So, pls help me to do that!! it's pretty cool. :)
20th Oct 2019, 4:25 PM
Daniel Amini
Daniel Amini - avatar
+ 1
import random, string #ALL PRINTABLE chars: a = 'ABCDEFGHabcdefgh123456789' paswrd = '' for p in range(15): paswrd += random.choice(a) print(paswrd) OK...!!! We have for example printed "DGCh49CaCAdDhaa" on our terminal. This password is vulnerable! because it has Consecutive Uppercase Letters("DGC"), Consecutive Lowercase Letters("haa"). I fixed many problems! I can remove duplicates! but I can't solve the consecutive characters...! :'(
20th Oct 2019, 4:43 PM
Daniel Amini
Daniel Amini - avatar
+ 1
Can't you create a 2D list, the first element has the uppercase, the second has lowercase and the third has the numbers the forth element has uppercase again..etc, loop through them and do random.choice from each element and 'append' to the string.. ahhh...just noticed the comment by Miika...great minds think alike.
20th Oct 2019, 7:09 PM
rodwynnejones
rodwynnejones - avatar
+ 1
hello mike. I did that! I made 3 strings a='ABC' , b='abc' and c='123' . BUT I can't introduce a variable that remembers which set the last character was drawn from and randomly select one of the other two. YES! this IDEA is best but I can't code it. I don't know... I even Googled it! I explode YouTube!! but I got nothing!
20th Oct 2019, 7:53 PM
Daniel Amini
Daniel Amini - avatar
+ 1
hi rodwynnejones I did it once. But it has a huge problem! the problem is uppercase, lowercase and number always repeated sequentially. for example if I execute your program we have "As3Sd4Df9Wp9" .... we have One upper, One lower and One number Sequentially forever!! Our password remains vulnerable!! The only thing we have to do is tell to our program that the first index is upper, middle one is lower and the third is number! DONE!! We have to write a program that do this job itself for us!! randomly!! impossible to guess! impossible to reverse engineering... I think we should use keyword "any"!!
21st Oct 2019, 3:19 PM
Daniel Amini
Daniel Amini - avatar
+ 1
Sorry Miika, I couldn't make it. Please do something for me before I break my monitor!! Programming dead-ends are the worst thing that happens for people! It is CRAZY!! I went to my bed! Hallelujah . . . x:(
24th Oct 2019, 10:23 AM
Daniel Amini
Daniel Amini - avatar
+ 1
Wooow!!!! Wooow!! Miika... I am working... I'll analysis your code letter by letter as soon as I arrive to home!! I ran your code!!! YOU DID IT...!!! woowww... You are my guardian angel . . . !! Thank you much more than your your time and your generosity. this question had driven me crazy.. you're my new best friend... best wishes! thanks again
24th Oct 2019, 2:09 PM
Daniel Amini
Daniel Amini - avatar
0
Try coding the password generator yourself, and then your code to this post. Even if you fail to, just share your attempt, and we'll help you fix what you're missing.
20th Oct 2019, 4:28 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
Share it in a file please, go to code playground, write this script, save it. Come back to this post, clicl edit, then post code, and select your code.
20th Oct 2019, 4:46 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
import random mylist = [['A', 'B', 'C', 'D'], ['a', 'b', 'c', 'd'], [1, 2, 3, 4]] * 3 mylist.append(mylist[0]) # Did this as the number 10 was in your range. mystring = "" for x in mylist: mystring += str(random.choice(x)) print(mystring)
20th Oct 2019, 8:17 PM
rodwynnejones
rodwynnejones - avatar
0
Isn't there a flaw in implementing what you are trying to do anyway? If the first character of a password is an uppercase letter, then the second character must be one of the other 68 characters (if using all punctuations too).. but if you include the uppercase still, then the second character can be any one of 94 characters again. Here what i would do...put the password in to a list constructor...send that then to random.shuffle then join them using ermmmmmmm.... join.
22nd Oct 2019, 4:10 PM
rodwynnejones
rodwynnejones - avatar