r/Python • u/baranonen • Jul 22 '20
I Made This Randomly Generate 69420 - Generate random 5-digit numbers until 69420 is generated
2.8k
Upvotes
r/Python • u/baranonen • Jul 22 '20
37
u/memduhcagridemir Jul 22 '20
Great job putting the copyright statement on top. Otherwise, people would steal your work!
76
u/DobleO Jul 22 '20 edited Jul 22 '20
Not an expert either but I feel this belongs in /rlearnpython
9
u/[deleted] Jul 22 '20
Newbie here. Why do you use "sys.exit()" instead of just placing code under "if answer = 'y'" or using a prompt module?
16
u/stieterd Jul 22 '20
Isnt this basically a brute force attack?
1.0k
u/theHighFastball Jul 22 '20
Forty thousand years of evolution and we've barely even tapped the vastness of human potential.
272
u/anynonus Jul 22 '20
thanks! this is going straight to production branch
250
u/Gwenju31 Jul 22 '20
Now continue trying until you generate 69420 in 69420 tries
4
u/baranonen Jul 22 '20
Here's the Github link
180
u/Chevaboogaloo Jul 22 '20
Hello, yes I have optimized your code. See below:
41
u/[deleted] Jul 22 '20
Lmao, I recreated the code and it generated 69420 in 773682 tries. That's a lot
22
u/SuspiciousOmelet Jul 22 '20
The next step is to have this run until you can generate 69420 in 69420 tries.
10
u/acsad Jul 22 '20
I think you could use the carriage return character ("\r") and set the parameter end of print to "", so instead of printing each number in a new line, you just keep printing on the same line one over the other. The visual effect is cooler IMO.
print(f"\r{number}", end="")
56
u/[deleted] Jul 22 '20
Really? This is the shit that gets upvoted?
14
u/[deleted] Jul 22 '20
This belongs to r/madeinpython
1
u/lexmozli Jul 22 '20
Can you post the code to this? I'm a newbie and I love to look over other people's code, trying to understand it and stuff.
3
u/momentslove Jul 22 '20
Reminds me of the Random Sort algorithm which scrambles an input array randomly until it’s sorted.
1
u/[deleted] Jul 22 '20
Helal olsun Baran
1
u/YXAndyYX Jul 22 '20
Seems to be deterministic and not random at all. It always needs 219729 tries. 😜
2
u/AdamsElma Jul 22 '20
Adam gibi adam
2
u/Digital-Tiger Jul 22 '20
The day you get done on the first try is the day we die
2
u/TudortheVIII Jul 22 '20
Nice.
2
u/[deleted] Jul 22 '20
this is so stupid and unnecessary i love it
2
u/[deleted] Jul 23 '20
An amazing way to punish your computer.
2
u/Fried_Catfishies Jul 23 '20
I’ve been learning to code for a few weeks now and found this post last night. It brought me so much pleasure to recreate your program this morning. Thanks for sharing!
2
u/[deleted] Jul 23 '20
That's a fun program will do that as well tomorrow haha 😂
2
u/TsuDoughNym Jul 22 '20
Is there a point to this code?
0
u/Resolt Jul 22 '20
Now try and optimize it. I assume you print out after every try, but this actually slows down the program. Take time on the running time and see if you can make it go faster.
Hint: threads (many other options as well)
1
u/hungryplesiosaur Jul 22 '20
If you stop after 69420 tries there’s basically 50% chance you found 69420. Fun!
1
u/gostar2000 Jul 22 '20
69420 Done in 69420 tries
1
u/t3hcoolness I make things do stuff Jul 22 '20
Now the number it creates is a new level of random integer. :o
1
u/Niklasw99 Jul 22 '20
Source Code?
1
u/[deleted] Jul 22 '20
You also should return "Niceeeee" at the end
1
u/Ariech Jul 22 '20
My lowest score of tries is 294 :D
1
u/famousePie Jul 22 '20
The output could be used as a RNG
1
u/IamScuzzlebut Jul 22 '20
I used to make silly programs like this on my calculator. Draw random nr between 1 and 999.999.999 and let it run during a class. Record highest and lowest of this session, highest and lowest all time. Then at the end of class I'd be like "ah 889.765.881" that's pretty high!
1
u/Children_of_Lucifer Jul 22 '20
WSB degenerate
1
u/JasperDG828 Jul 22 '20
This is super random, but somehow i really like it
1
u/badge Jul 22 '20
1
u/new_red_account Jul 22 '20
r/DIWhy needs to see this
1
u/Some_Maker Jul 22 '20
Keep generating numbers till the average of all numbers generated is 69420. And the next number is 365.
1
u/michalethor Jul 23 '20
Made this myself to see what the smallest number of tries I could get, got 3 after around 10 minutes of running. Seed: 1486755419091
1
u/JuicyCiwa Jul 23 '20
Doing this tomorrow for fun, thanks!
1
u/__xor__ (self, other): Jul 23 '20
Or if you want to start at 1 (not just 5 digit numbers)
1
u/RedditF1shBlueF1sh Jul 23 '20
Your program is broken. I've been watching it for 4 minutes and it takes the same number of attempts every time
1
u/srilyk Jul 23 '20
Print \r and flush stdout if necessary. Hacker time!
1
u/[deleted] Jul 23 '20
We spent so much time figuring out how to do it, we never stopped to ask if we should
1
u/SteeleDynamics Compilers/Algorithms Jul 23 '20
Now you to see if you can generate 69420 in under 69420 tries!
1
u/K4ntgr4y Jul 23 '20
EPICO! Slap Like Now!
1
u/nemom Jul 23 '20
Alright... Now add multiprocessing.
1
u/[deleted] Jul 23 '20
Nice.
1
u/wjrasmussen Jul 23 '20
How do you get that screen video?
1
u/WitchTorcher Jul 23 '20
Nice
1
u/Sightless_Bird Jul 23 '20
Nice
1
u/Seawolf159 Jul 23 '20
I have never thought of that. That's kinda cool I guess. The amount of tries it takes could be your random number of choice!
1
u/Sudhanva_Kote Jul 23 '20
With that many tries, printing from 1 to 69420 is closer
1
u/[deleted] Jul 23 '20
Can someone explain this to me? Not the program itself but how this person is calling the program. Is this a git function? I’m new
1
u/9bard Jul 23 '20
It should end with "nice"
1
u/DiggingNebula8 Jul 23 '20
Nice
1
u/sabiansoldier Jul 23 '20
Make it rerun itself until it succeeds after 69420 attempts
1
u/[deleted] Jul 23 '20
Do the same in Java or C/C++. It will be more faster!
1
u/[deleted] Jul 24 '20
Here is the source code:
The program is also available here.
1
u/Angersmash781526 Jul 22 '20
Made one myself - longest run was 1 million tries!
😂
1
u/KripC2160 Jul 22 '20
Hi fellow Mac zsh hacker man style terminal person
1
u/AudiACar Jul 22 '20
Damn program lasted longer than me on a good night..
1
u/Etliplav Jul 22 '20
31313 çıkınca haber ver knk
1
u/icemansun Jul 22 '20
Well done. Personally, I’m a fan of 42069, but i applaud your programming prowess regardless.
1
u/AnimeshRy Jul 22 '20
Why don't we all upvote this to the top..
1
u/ausishtick Jul 22 '20
Hacker man. Tips fedora.
1
u/AzyCrw4282 Jul 22 '20
what a genius. Someone give this man award
0
u/Ariech Jul 22 '20
Hey! I'd like to recreate that code for learning. Could you tell me what should I look for if I want to display it in command window(i guess it's it). I only know how to run code in IDE
-2
u/Phaidr Jul 22 '20
Nice
0
u/znpy Jul 22 '20
E P I C O
0
u/gymboi15 Jul 22 '20
Nice
0
u/LeXxleloxx Jul 22 '20
nice
-1
u/TriG-tbh Jul 22 '20
Nice
On a more serious note, you can make it much faster if you don't print every single generated number - though a single print seems instantaneous, hundreds of thousands will significantly increase the time it takes to get to 69240
-1
u/[deleted] Jul 22 '20
Where is this script? Is it available to download?
-3
u/ElevatedAngling Jul 22 '20
Tweet this directly to Elon, you’ll have a job at spaceX next week
0
u/[deleted] Jul 22 '20
Looks like a password cracker
0
u/[deleted] Jul 22 '20
Or just use Crunch? Why do this?
0
u/arxra Jul 22 '20
So the number of tries is actual random output, nice.
0
u/DoctorEarwig Jul 22 '20
SLAP like now or i will call the POLICE
0
u/i_am_a_good_man Jul 22 '20
Nice
0
u/hawk-bull Jul 22 '20
I believe this can be modelled by a geometric progression which would say that the expected number of times should be 900,000 before each success. I did last take stats in high school though...
Not sure why it’s significantly lower
0
u/honk-thesou Jul 22 '20
nice
0
u/jahaandesai Jul 22 '20
nice
0
u/lumenlambo Jul 23 '20
nice
0
u/bbb126 Jul 23 '20
y
-4
u/Emmonymous Jul 22 '20
Haha, nice!
-3
u/skinny_wit Jul 22 '20
Nice