Testing Mega Sena Games

Asked

Viewed 398 times

4

My teacher asked me to generate a mega sena bet generator. I did, and modesty part turned out pretty cool:

from time import sleep
from random import sample
palpite = list()
a = []
print('='*40)
print('=========PALPITES DA MEGA SENA==========')
print('='*40)
print()
sleep(0.1)
c = []
cont = 0
for i in range(1,61):
    c.append(i)
pergunta = int(input('\033[35mQuantos palpites deseja processar? '))
for j in range(0, pergunta):
    palpite.append(sample(c,6))

print()
palpite.sort()
sleep(1)
print('=-'*30)
print('#'*35)
print(f'sortendo {pergunta} numeros')
print('#'*35)
print('=-'*30)
print()
sleep(1.5)
for d in palpite:
    d.sort()
    cont += 1
    sleep(1)
    print(f'{cont}º Jogo = {d}')
sleep(1.5)
print()
print('-='*30)
print('\033[1;32m         >>>>> BOA SORTE <<<<<<   ')
print('Fim')
print('\033[31m^'*45)

But then a question came to me: I am a player until I am a regular of the mega sena (at least 1 time a week I make a bet). Is it really possible to win? Then I created a program to test:

from random import sample
numero1 = []
numero2 = []
jogo1 = []
jogo2 = []
for n1 in range(1,61):
    numero1.append(n1)
for n2 in range(1,61):
    numero2.append(n2)
while True:
    jogo1.append(sample(numero1,6))
    jogo2.append(sample(numero2,6))
    for m in jogo1:
        m.sort()
    for z in jogo2:
        z.sort()
    if m == z:
        print(m)
        print(z)
        break
print('fim')

But it didn’t work. It didn’t go wrong, it seems like it was running, but I’m not sure. I waited about 5 minutes, and nothing. Is it really impossible, or is my program simply wrong?

I’m using the Pycharm.

  • for some reason, this question was extremely messy. I don’t know what happened, since when I was writing it was well formatted

  • 2

    Being a regular player, you should know that the probability of selling is extremely small, I entered is normal that it takes until two draws are equal.

  • Welcome to Stack Overflow, Douglas! I saw that you added new questions to this, already answered - I would suggest that you mark the answer below as accepted by clicking the arrow, or if you have any secondary questions, make a comment/ask for clarification; regarding your new questions, please create a new question, trying to present one problem at a time - the purpose is to keep the site organized, and that other users can use your question and answers to learn as well! :)

  • I took the liberty of reversing your edit - you can click on the link edited... to review the text you had written, if you want to repurpose for a new question - thank you for understanding!

  • Blogger, I read your comment and thank you deeply for the corrections. Thank you very much, and nice presentation on your profile. Worthy of approval by the faculty of Sirius. DO NOT PANIC!!!. I want to mark this answer as accepted. You asked me to click the arrow... What arrow?

  • In the answer, in the upper left corner there is an arrow up upvote, the votes that were cast (at time 5), an arrow down downvote and below a check mark - click on it; for people to receive notification of their comment here, type their name with a @before, for example: @Blogger

Show 1 more comment

1 answer

6

There are 50.063.860 possibilities of results in this game of 6 numbers. A chance to come out a combination [a1,a2,a3,a4,a5,a6] expected is to 1/50.063.860 = 0,00000002 which corresponds to 0,000002%. That is, every 50,063,860 games, you are expected to win 1.

I modified your test code a bit (save all the selected values and go through them all with a for and . Sort() does not seem like a good idea):

from random import sample
import time

numero1 = []
for n1 in range(1,61):
    numero1.append(n1)

tentativas = 0
start = time.time()
while True:
    tentativas += 1
    if tentativas % 500000 == 0:
        print('Tentativas:', tentativas, end = ' | ')
        print('Tempo:', time.time()-start)
    m = sample(numero1, k=6)
    m.sort()
    z = sample(numero1, k=6)
    z.sort()
    if m == z:
        print('Tentativas:', tentativas)
        print('Tempo:', time.time()-start)
        print(m)
        print(z)
        break
print('fim')

I ran it a few times and got the results:

Sample 1:

...
Tentativas: 89500000 | Tempo: 1628.135265827179
Tentativas: 90000000 | Tempo: 1637.143269777298
Tentativas: 90500000 | Tempo: 1645.9052894115448
KeyboardInterrupt

Sample 2:

...
Tentativas: 29500000 | Tempo: 546.6875867843628
Tentativas: 30000000 | Tempo: 556.0576255321503
Tentativas: 30500000 | Tempo: 565.2926483154297
KeyboardInterrupt

Sample 3:

Tentativas: 500000 | Tempo: 9.574995756149292
Tentativas: 1000000 | Tempo: 18.5190167427063
Tentativas: 1009879
Tempo: 18.727997303009033
[10, 13, 28, 37, 49, 56]
[10, 13, 28, 37, 49, 56]
fim

Now when I change z to z = [1,2,3,4,5,6]:

Sample 1:

...
Tentativas: 10000000 | Tempo: 94.66205024719238
Tentativas: 10500000 | Tempo: 99.3870267868042
Tentativas: 10634304
Tempo: 100.61703157424927
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
fim

Sample 2:

...
Tentativas: 40000000 | Tempo: 381.7722237110138
Tentativas: 40500000 | Tempo: 386.4262237548828
Tentativas: 40534342
Tempo: 386.7422297000885
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
fim

Moral of the story: your code isn’t wrong and it’s not impossible to win, assuming the game is random.

  • Caraca!!! I knew it was hard to win in the mega, but after that Voce uses logic? Raccoon. is scary...

  • I’m really scared... I’ll post this on the Course forum and video and score the Guanabara.... I’m very scared. It’s almost impossible to win. Almost.

  • Thanks for the Alexciuffa medal

Browser other questions tagged

You are not signed in. Login or sign up in order to post.