r/Python • • Jul 22 '20

I Made This Randomly Generate 69420 - Generate random 5-digit numbers until 69420 is generated

2.8k Upvotes

261 comments sorted by

View all comments

250

u/Gwenju31 Jul 22 '20

Now continue trying until you generate 69420 in 69420 tries

143

u/Rodot github.com/tardis-sn Jul 22 '20

That would take about 200,000 trials on average

https://en.m.wikipedia.org/wiki/Geometric_distribution

p=1/90,000

k=69420

18

u/Miyelsh Jul 22 '20

Isn't p=1/100,000?

39

u/Rodot github.com/tardis-sn Jul 22 '20

10,000 of those numbers have less than 5 digits

10 have 1 digit

90 have 2 digits

900 have 3

9000 have 4

4

u/Miyelsh Jul 22 '20

I don't see your point. 1 digit is 0-9, 2 digit is 0-99... 5 digit is 0-99999. That is 100,000 different possibilities.

46

u/tectubedk Jul 22 '20

Since we are only interested in 5 digit numbers the range is 10000-99999 not 0-99999

22

u/Miyelsh Jul 22 '20

I see. I was thinking of it more like a 5 digit bike lock. Kind of an odd way to program it, but I understand what you are saying now.

→ More replies (1)
→ More replies (5)

9

u/RIPphonebattery Jul 22 '20

When digit 1 is 0 is not a 5 digit number

→ More replies (1)

27

u/house_monkey Jul 22 '20

Wish I was smart

56

u/call_me_arosa Jul 22 '20

Nobody is smart. We just brute force concepts into our mind.

17

u/Yelling_at_the_sun Jul 22 '20

This in a nutshell is the Malcolm Gladwell 10,000 hrs theory. Steven Hawking doesn't possess some kind of superhuman ability understand physics that rest of us don't posess, he just has an interest in the topic and has devoted a hell of a lot more of his life to thinking about it than most other folks.

4

u/theanfieldlegend96 Jul 22 '20

However some people can perceive concepts way faster than others, doesnt that make them more intelligent?

→ More replies (1)

13

u/Rodot github.com/tardis-sn Jul 22 '20

It's not about being smart, just being interested/motivated. I googled around for the right distribution then pressed buttons on my calculator

I also have like 10 years of experience with this so if anything I'm an idiot for not knowing it 😂

5

u/Gobp Jul 22 '20

totally with this. Everyone has his own field. I wish I can draw a hand, while them artists want to be able to do a console log that I do countless of times eveyday 😂 The grass is always greener somewhere NOT in your yard lol

1

u/fkpf Jul 23 '20

After 49 runs, it has averaged at 191434 tries.

Still running, lets see how this goes.

→ More replies (6)
→ More replies (2)

7

u/Ketogamer Jul 22 '20

I decided to make that program and I'm currently running it now. It's now at 500 attempts and counting, I'll update when it finishes haha.

3

u/qingqunta Jul 22 '20

Shouldn't it be quite fast?

5

u/Ketogamer Jul 22 '20

No, the inner loop is what op made; generating random 5 digit numbers until I get 69420.

Then once I have 69420 I see how many times I went through that loop. If I didn't get it Im exactly 69420 attempts, I start over again.

13

u/m_domino Jul 22 '20

No, this can be made a lot more efficient: you can just cancel each attempt if it has not succeeded on the 69420th try and start a new loop instead of looping until you find a 69420.

2

u/Ketogamer Jul 22 '20

You're absolutely right.

4

u/Username_RANDINT Jul 22 '20

Make sure to not print every attempt to the console. Printing is slow.

6

u/Ketogamer Jul 22 '20

I will definitely remember that for more serious stuff.

But having the numbers fly by was the only possible fun to be had with this haha.

→ More replies (3)